📄 device_main.c
字号:
pDevice->abyOFDMDefaultPwr[ii+CB_MAX_CHANNEL_24G+1] = SROMbyReadEmbedded(pDevice->PortOffset, (BYTE)(ii + EEP_OFS_OFDMA_PWR_dBm));
}
CARDvInitChannelTable((PVOID)pDevice);
if (pDevice->byLocalID > REV_ID_VT3253_B1) {
MACvSelectPage1(pDevice->PortOffset);
VNSvOutPortB(pDevice->PortOffset + MAC_REG_MSRCTL + 1, (MSRCTL1_TXPWR | MSRCTL1_CSAPAREN));
MACvSelectPage0(pDevice->PortOffset);
}
// use relative tx timeout and 802.11i D4
MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_CFG, (CFG_TKIPOPT | CFG_NOTXTIMEOUT));
// set performance parameter by registry
MACvSetShortRetryLimit(pDevice->PortOffset, pDevice->byShortRetryLimit);
MACvSetLongRetryLimit(pDevice->PortOffset, pDevice->byLongRetryLimit);
// reset TSF counter
VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
// enable TSF counter
VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
// initialize BBP registers
BBbVT3253Init(pDevice);
if (pDevice->bUpdateBBVGA) {
pDevice->byBBVGACurrent = pDevice->abyBBVGA[0];
pDevice->byBBVGANew = pDevice->byBBVGACurrent;
BBvSetVGAGainOffset(pDevice, pDevice->abyBBVGA[0]);
}
BBvSetRxAntennaMode(pDevice->PortOffset, pDevice->byRxAntennaMode);
BBvSetTxAntennaMode(pDevice->PortOffset, pDevice->byTxAntennaMode);
pDevice->byCurrentCh = 0;
//pDevice->NetworkType = Ndis802_11Automode;
// Set BB and packet type at the same time.
// Set Short Slot Time, xIFS, and RSPINF.
if (pDevice->uConnectionRate == RATE_AUTO) {
pDevice->wCurrentRate = RATE_54M;
} else {
pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
}
// default G Mode
VNTWIFIbConfigPhyMode(pDevice->pMgmt, PHY_TYPE_11G);
VNTWIFIbConfigPhyMode(pDevice->pMgmt, PHY_TYPE_AUTO);
pDevice->bRadioOff = FALSE;
pDevice->byRadioCtl = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_RADIOCTL);
pDevice->bHWRadioOff = FALSE;
if (pDevice->byRadioCtl & EEP_RADIOCTL_ENABLE) {
// Get GPIO
MACvGPIOIn(pDevice->PortOffset, &pDevice->byGPIO);
if ((BITbIsBitOn(pDevice->byGPIO,GPIO0_DATA) && BITbIsBitOff(pDevice->byRadioCtl, EEP_RADIOCTL_INV)) ||
(BITbIsBitOff(pDevice->byGPIO,GPIO0_DATA) && BITbIsBitOn(pDevice->byRadioCtl, EEP_RADIOCTL_INV))) {
pDevice->bHWRadioOff = TRUE;
}
}
if ((pDevice->bHWRadioOff == TRUE) || (pDevice->bRadioControlOff == TRUE)) {
CARDbRadioPowerOff(pDevice);
}
}
// get Permanent network address
SROMvReadEtherAddress(pDevice->PortOffset, pDevice->abyCurrentNetAddr);
DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Network address = %02x-%02x-%02x=%02x-%02x-%02x\n",
pDevice->abyCurrentNetAddr[0],
pDevice->abyCurrentNetAddr[1],
pDevice->abyCurrentNetAddr[2],
pDevice->abyCurrentNetAddr[3],
pDevice->abyCurrentNetAddr[4],
pDevice->abyCurrentNetAddr[5]);
// reset Tx pointer
CARDvSafeResetRx(pDevice);
// reset Rx pointer
CARDvSafeResetTx(pDevice);
if (pDevice->byLocalID <= REV_ID_VT3253_A1) {
MACvRegBitsOn(pDevice->PortOffset, MAC_REG_RCR, RCR_WPAERR);
}
pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
// Turn On Rx DMA
MACvReceive0(pDevice->PortOffset);
MACvReceive1(pDevice->PortOffset);
// start the adapter
MACvStart(pDevice->PortOffset);
netif_stop_queue(pDevice->dev);
}
static VOID device_init_diversity_timer(PSDevice pDevice) {
init_timer(&pDevice->TimerSQ3Tmax1);
pDevice->TimerSQ3Tmax1.data = (ULONG)pDevice;
pDevice->TimerSQ3Tmax1.function = (TimerFunction)TimerSQ3CallBack;
pDevice->TimerSQ3Tmax1.expires = RUN_AT(HZ);
init_timer(&pDevice->TimerSQ3Tmax2);
pDevice->TimerSQ3Tmax2.data = (ULONG)pDevice;
pDevice->TimerSQ3Tmax2.function = (TimerFunction)TimerSQ3CallBack;
pDevice->TimerSQ3Tmax2.expires = RUN_AT(HZ);
init_timer(&pDevice->TimerSQ3Tmax3);
pDevice->TimerSQ3Tmax3.data = (ULONG)pDevice;
pDevice->TimerSQ3Tmax3.function = (TimerFunction)TimerState1CallBack;
pDevice->TimerSQ3Tmax3.expires = RUN_AT(HZ);
return;
}
#ifndef PRIVATE_OBJ
static int
device_found1(struct pci_dev *pcid, const struct pci_device_id *ent)
{
static BOOL bFirst = TRUE;
struct net_device* dev = NULL;
PCHIP_INFO pChip_info = (PCHIP_INFO)ent->driver_data;
PSDevice pDevice;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
int rc;
#endif
if (device_nics ++>= MAX_UINTS) {
printk(KERN_NOTICE DEVICE_NAME ": already found %d NICs\n", device_nics);
return -ENODEV;
}
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
dev = alloc_etherdev(0);
#else
dev = init_etherdev(dev, 0);
#endif
if (dev == NULL) {
printk(KERN_ERR DEVICE_NAME ": allocate net device failed \n");
return -ENODEV;
}
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
// Chain it all together
SET_MODULE_OWNER(dev);
SET_NETDEV_DEV(dev, &pcid->dev);
#endif
if (bFirst) {
printk(KERN_NOTICE "%s Ver. %s\n",DEVICE_FULL_DRV_NAM, DEVICE_VERSION);
printk(KERN_NOTICE "Copyright (c) 2003 VIA Networking Technologies, Inc.\n");
bFirst=FALSE;
}
if (!device_init_info(pcid, &pDevice, pChip_info)) {
return -ENOMEM;
}
pDevice->dev = dev;
pDevice->next_module = root_device_dev;
root_device_dev = dev;
dev->priv = pDevice;
dev->irq = pcid->irq;
if (pci_enable_device(pcid)) {
device_free_info(pDevice);
return -ENODEV;
}
if (device_get_pci_info(pDevice,pcid) == FALSE) {
printk(KERN_ERR DEVICE_NAME ": Failed to find PCI device.\n");
device_free_info(pDevice);
return -ENODEV;
}
pDevice->PortOffset = (DWORD)ioremap(pDevice->memaddr & PCI_BASE_ADDRESS_MEM_MASK, pDevice->io_size);
if(pDevice->PortOffset == 0) {
printk(KERN_ERR DEVICE_NAME ": Failed to IO remapping ..\n");
device_free_info(pDevice);
return -ENODEV;
}
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
rc = pci_request_regions(pcid, DEVICE_NAME);
if (rc) {
printk(KERN_ERR DEVICE_NAME ": Failed to find PCI device\n");
device_free_info(pDevice);
return -ENODEV;
}
#else
if (check_region(pDevice->ioaddr, pDevice->io_size)) {
printk(KERN_ERR DEVICE_NAME ": Failed to find PCI device\n");
device_free_info(pDevice);
return -ENODEV;
}
request_region(pDevice->ioaddr, pDevice->io_size, DEVICE_NAME);
#endif
dev->base_addr = pDevice->ioaddr;
#ifdef IO_MAP
pDevice->PortOffset = pDevice->ioaddr;
#endif
// do reset
if (!MACbSoftwareReset(pDevice->PortOffset)) {
printk(KERN_ERR DEVICE_NAME ": Failed to access MAC hardware..\n");
device_free_info(pDevice);
return -ENODEV;
}
// initial to reload eeprom
MACvInitialize(pDevice->PortOffset);
MACvReadEtherAddress(pDevice->PortOffset, dev->dev_addr);
device_get_options(pDevice, device_nics-1, dev->name);
device_set_options(pDevice);
//Mask out the options cannot be set to the chip
pDevice->sOpts.flags &= pChip_info->flags;
//Enable the chip specified capbilities
pDevice->flags = pDevice->sOpts.flags | (pChip_info->flags & 0xFF000000UL);
pDevice->tx_80211 = device_dma0_tx_80211;
pDevice->sMgmtObj.pAdapter = (PVOID)pDevice;
pDevice->pMgmt = &(pDevice->sMgmtObj);
dev->irq = pcid->irq;
dev->open = device_open;
dev->hard_start_xmit = device_xmit;
dev->stop = device_close;
dev->get_stats = device_get_stats;
dev->set_multicast_list = device_set_multi;
dev->do_ioctl = device_ioctl;
#ifdef WIRELESS_EXT
dev->get_wireless_stats = iwctl_get_wireless_stats;
#if WIRELESS_EXT > 12
dev->wireless_handlers = (struct iw_handler_def *)&iwctl_handler_def;
// netdev->wireless_handlers = NULL;
#endif /* WIRELESS_EXT > 12 */
#endif /* WIRELESS_EXT */
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
rc = register_netdev(dev);
if (rc)
{
printk(KERN_ERR DEVICE_NAME " Failed to register netdev\n");
device_free_info(pDevice);
return -ENODEV;
}
#endif
device_print_info(pDevice);
pci_set_drvdata(pcid, pDevice);
return 0;
}
static void device_print_info(PSDevice pDevice)
{
struct net_device* dev=pDevice->dev;
DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO "%s: %s\n",dev->name, get_chip_name(pDevice->chip_id));
DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO "%s: MAC=%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
dev->name,
dev->dev_addr[0],dev->dev_addr[1],dev->dev_addr[2],
dev->dev_addr[3],dev->dev_addr[4],dev->dev_addr[5]);
#ifdef IO_MAP
DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO" IO=0x%lx ",(ULONG) pDevice->ioaddr);
DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO" IRQ=%d \n", pDevice->dev->irq);
#else
DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO" IO=0x%lx Mem=0x%lx ",(ULONG) pDevice->ioaddr,(ULONG) pDevice->PortOffset);
DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO" IRQ=%d \n", pDevice->dev->irq);
#endif
}
static BOOL device_init_info(struct pci_dev* pcid, PSDevice* ppDevice,
PCHIP_INFO pChip_info) {
PSDevice p;
*ppDevice = kmalloc(sizeof(DEVICE_INFO),GFP_ATOMIC);
if (*ppDevice == NULL)
return FALSE;
memset(*ppDevice,0,sizeof(DEVICE_INFO));
if (pDevice_Infos == NULL) {
pDevice_Infos =*ppDevice;
}
else {
for (p=pDevice_Infos;p->next!=NULL;p=p->next)
do {} while (0);
p->next = *ppDevice;
(*ppDevice)->prev = p;
}
(*ppDevice)->pcid = pcid;
(*ppDevice)->chip_id = pChip_info->chip_id;
(*ppDevice)->io_size = pChip_info->io_size;
(*ppDevice)->nTxQueues = pChip_info->nTxQueue;
(*ppDevice)->multicast_limit =32;
spin_lock_init(&((*ppDevice)->lock));
return TRUE;
}
static BOOL device_get_pci_info(PSDevice pDevice, struct pci_dev* pcid) {
U16 pci_cmd;
U8 b;
UINT cis_addr;
pci_read_config_byte(pcid, PCI_REVISION_ID, &pDevice->byRevId);
pci_read_config_word(pcid, PCI_SUBSYSTEM_ID,&pDevice->SubSystemID);
pci_read_config_word(pcid, PCI_SUBSYSTEM_VENDOR_ID, &pDevice->SubVendorID);
pci_read_config_word(pcid, PCI_COMMAND, (u16 *) & (pci_cmd));
pci_set_master(pcid);
pDevice->memaddr = pci_resource_start(pcid,0);
pDevice->ioaddr = pci_resource_start(pcid,1);
cis_addr = pci_resource_start(pcid,2);
pDevice->pcid = pcid;
pci_read_config_byte(pcid, PCI_REG_COMMAND, &b);
pci_write_config_byte(pcid, PCI_REG_COMMAND, (b|COMMAND_BUSM));
return TRUE;
}
static void device_free_info(PSDevice pDevice) {
PSDevice ptr;
struct net_device* dev=pDevice->dev;
ASSERT(pDevice);
if (pDevice_Infos==NULL)
return;
for (ptr=pDevice_Infos;ptr && (ptr!=pDevice);ptr=ptr->next)
do {} while (0);
if (ptr==pDevice) {
if (ptr==pDevice_Infos)
pDevice_Infos=ptr->next;
else
ptr->prev->next=ptr->next;
}
else {
DEVICE_PRT(MSG_LEVEL_ERR, KERN_ERR "info struct not found\n");
return;
}
#ifdef HOSTAP
if (dev)
hostap_set_hostapd(pDevice, 0, 0);
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -