/* ======================================================================== Routine Description: Init AP-Client function. Arguments: ad_p points to our adapter main_dev_p points to the main BSS network interface Return Value: None Note: 1. Only create and initialize virtual network interfaces. 2. No main network interface here. ======================================================================== */ VOID RT28xx_ApCli_Init( IN PRTMP_ADAPTER ad_p, IN PNET_DEV main_dev_p) { #define APCLI_MAX_DEV_NUM 32 PNET_DEV new_dev_p; // VIRTUAL_ADAPTER *apcli_ad_p; INT apcli_index; RTMP_OS_NETDEV_OP_HOOK netDevOpHook; APCLI_STRUCT *pApCliEntry; /* sanity check to avoid redundant virtual interfaces are created */ if (ad_p->flg_apcli_init != FALSE) return; /* init */ for(apcli_index = 0; apcli_index < MAX_APCLI_NUM; apcli_index++) ad_p->ApCfg.ApCliTab[apcli_index].dev = NULL; /* create virtual network interface */ for(apcli_index = 0; apcli_index < MAX_APCLI_NUM; apcli_index++) { new_dev_p = RtmpOSNetDevCreate(ad_p, INT_APCLI, apcli_index, sizeof(PRTMP_ADAPTER), INF_APCLI_DEV_NAME); RTMP_OS_NETDEV_SET_PRIV(new_dev_p, ad_p); pApCliEntry = &ad_p->ApCfg.ApCliTab[apcli_index]; /* init MAC address of virtual network interface */ COPY_MAC_ADDR(pApCliEntry->CurrentAddress, ad_p->CurrentAddress); pApCliEntry->CurrentAddress[ETH_LENGTH_OF_ADDRESS - 1] = (pApCliEntry->CurrentAddress[ETH_LENGTH_OF_ADDRESS - 1] + ad_p->ApCfg.BssidNum + MAX_MESH_NUM) & 0xFF; /* init operation functions */ NdisZeroMemory(&netDevOpHook, sizeof(RTMP_OS_NETDEV_OP_HOOK)); netDevOpHook.open = ApCli_VirtualIF_Open; netDevOpHook.stop = ApCli_VirtualIF_Close; netDevOpHook.xmit = ApCli_VirtualIF_PacketSend; netDevOpHook.ioctl = ApCli_VirtualIF_Ioctl; netDevOpHook.priv_flags = INT_APCLI; /* we are virtual interface */ netDevOpHook.needProtcted = TRUE; NdisMoveMemory(&netDevOpHook.devAddr[0], &pApCliEntry->CurrentAddress[0], MAC_ADDR_LEN); /* register this device to OS */ RtmpOSNetDevAttach(new_dev_p, &netDevOpHook); /* backup our virtual network interface */ pApCliEntry->dev = new_dev_p; #ifdef WSC_AP_SUPPORT pApCliEntry->WscControl.pAd = ad_p; if (pApCliEntry->WscControl.WscEnrolleePinCode == 0) pApCliEntry->WscControl.WscEnrolleePinCode = GenerateWpsPinCode(ad_p, TRUE, 0); NdisZeroMemory(pApCliEntry->WscControl.EntryAddr, MAC_ADDR_LEN); WscInit(ad_p, TRUE, apcli_index); #endif // WSC_AP_SUPPORT // } /* End of for */ ad_p->flg_apcli_init = TRUE; }
VOID WDS_Init( IN PRTMP_ADAPTER pAd, IN RTMP_OS_NETDEV_OP_HOOK *pNetDevOps) { INT index; PNET_DEV pWdsNetDev; /* sanity check to avoid redundant virtual interfaces are created */ if (pAd->flg_wds_init != FALSE) return; for(index = 0; index < MAX_WDS_ENTRY; index++) { UINT32 MC_RowID = 0, IoctlIF = 0; #ifdef MULTIPLE_CARD_SUPPORT MC_RowID = pAd->MC_RowID; #endif /* MULTIPLE_CARD_SUPPORT */ #ifdef HOSTAPD_SUPPORT IoctlIF = pAd->IoctlIF; #endif /* HOSTAPD_SUPPORT */ pWdsNetDev = RtmpOSNetDevCreate(MC_RowID, &IoctlIF, INT_WDS, index, sizeof(PRTMP_ADAPTER), INF_WDS_DEV_NAME); #ifdef HOSTAPD_SUPPORT pAd->IoctlIF = IoctlIF; #endif /* HOSTAPD_SUPPORT */ if (pWdsNetDev == NULL) { /* allocation fail, exit */ DBGPRINT(RT_DEBUG_ERROR, ("Allocate network device fail (WDS)...\n")); break; } else { PMAC_TABLE_ENTRY pWdsEntry; pWdsEntry = &pAd->MacTab.Content[pAd->WdsTab.WdsEntry[index].MacTabMatchWCID]; DBGPRINT(RT_DEBUG_TRACE, ("The new WDS interface MAC = %02X:%02X:%02X:%02X:%02X:%02X\n", PRINT_MAC(pWdsEntry->Addr))); } NdisZeroMemory(&pAd->WdsTab.WdsEntry[index].WdsCounter, sizeof(WDS_COUNTER)); RTMP_OS_NETDEV_SET_PRIV(pWdsNetDev, pAd); pAd->WdsTab.WdsEntry[index].PhyMode = 0xff; pAd->WdsTab.WdsEntry[index].dev = pWdsNetDev; pNetDevOps->priv_flags = INT_WDS; /* we are virtual interface */ pNetDevOps->needProtcted = TRUE; /* Register this device */ RtmpOSNetDevAttach(pAd->OpMode, pWdsNetDev, pNetDevOps); pAd->WdsTab.WdsEntry[index].PhyMode = 0xff; pAd->WdsTab.WdsEntry[index].dev = pWdsNetDev; } pAd->flg_wds_init = TRUE; DBGPRINT(RT_DEBUG_TRACE, ("Total Allocate %d WDS interfaces!\n", index)); }
// Register WDS interface VOID RT28xx_WDS_Init( IN PRTMP_ADAPTER pAd, IN PNET_DEV net_dev) { INT index; PNET_DEV pWdsNetDev; RTMP_OS_NETDEV_OP_HOOK netDevOpHook; /* sanity check to avoid redundant virtual interfaces are created */ if (pAd->flg_wds_init != FALSE) return; for(index = 0; index < MAX_WDS_ENTRY; index++) { pWdsNetDev = RtmpOSNetDevCreate(pAd, INT_WDS, index, sizeof(PRTMP_ADAPTER), INF_WDS_DEV_NAME); if (pWdsNetDev == NULL) { /* allocation fail, exit */ DBGPRINT(RT_DEBUG_ERROR, ("Allocate network device fail (WDS)...\n")); break; } else { PMAC_TABLE_ENTRY pWdsEntry; pWdsEntry = &pAd->MacTab.Content[pAd->WdsTab.WdsEntry[index].MacTabMatchWCID]; DBGPRINT(RT_DEBUG_TRACE, ("The new WDS interface MAC = %02X:%02X:%02X:%02X:%02X:%02X\n", PRINT_MAC(pWdsEntry->Addr))); } NdisZeroMemory(&pAd->WdsTab.WdsEntry[index].WdsCounter, sizeof(WDS_COUNTER)); RTMP_OS_NETDEV_SET_PRIV(pWdsNetDev, pAd); pAd->WdsTab.WdsEntry[index].PhyMode = 0xff; pAd->WdsTab.WdsEntry[index].dev = pWdsNetDev; NdisZeroMemory((PUCHAR)&netDevOpHook, sizeof(RTMP_OS_NETDEV_OP_HOOK)); netDevOpHook.open = WdsVirtualIF_open; netDevOpHook.stop = WdsVirtualIF_close; netDevOpHook.xmit = WdsVirtualIFSendPackets; netDevOpHook.ioctl = WdsVirtualIF_ioctl; netDevOpHook.priv_flags = INT_WDS; /* we are virtual interface */ netDevOpHook.needProtcted = TRUE; netDevOpHook.get_stats = RT28xx_get_wds_ether_stats; NdisMoveMemory(&netDevOpHook.devAddr[0], RTMP_OS_NETDEV_GET_PHYADDR(net_dev), MAC_ADDR_LEN); DBGPRINT(RT_DEBUG_TRACE, ("The new WDS interface MAC = %02X:%02X:%02X:%02X:%02X:%02X\n", PRINT_MAC(netDevOpHook.devAddr))); // Register this device RtmpOSNetDevAttach(pWdsNetDev, &netDevOpHook); pAd->WdsTab.WdsEntry[index].PhyMode = 0xff; pAd->WdsTab.WdsEntry[index].dev = pWdsNetDev; } pAd->flg_wds_init = TRUE; DBGPRINT(RT_DEBUG_TRACE, ("Total Allocate %d WDS interfaces!\n", index)); }
VOID RTMP_CFG80211_VirtualIF_Init( IN struct rtmp_adapter *pAd, IN CHAR *pDevName, IN uint32_t DevType) { struct RTMP_OS_NETDEV_OP_HOOK netDevHook, *pNetDevOps; struct net_device *new_dev_p; struct rtmp_wifi_dev *wdev; CHAR preIfName[12]; UINT devNameLen = strlen(pDevName); UINT preIfIndex = pDevName[devNameLen-1] - 48; struct mt7612u_cfg80211_cb *p80211CB = pAd->pCfg80211_CB; struct wireless_dev *pWdev; uint32_t MC_RowID = 0, IoctlIF = 0, Inf = INT_P2P; memset(preIfName, 0, sizeof(preIfName)); memcpy(preIfName, pDevName, devNameLen-1); pNetDevOps=&netDevHook; DBGPRINT(RT_DEBUG_TRACE, ("%s ---> (%s, %s, %d)\n", __FUNCTION__, pDevName, preIfName, preIfIndex)); /* init operation functions and flags */ memset(&netDevHook, 0, sizeof(netDevHook)); netDevHook.open = CFG80211_VirtualIF_Open; /* device opem hook point */ netDevHook.stop = CFG80211_VirtualIF_Close; /* device close hook point */ netDevHook.xmit = CFG80211_VirtualIF_PacketSend; /* hard transmit hook point */ netDevHook.ioctl = CFG80211_VirtualIF_Ioctl; /* ioctl hook point */ #if WIRELESS_EXT >= 12 //netDevHook.iw_handler = (void *)&rt28xx_ap_iw_handler_def; #endif /* WIRELESS_EXT >= 12 */ new_dev_p = RtmpOSNetDevCreate(MC_RowID, &IoctlIF, Inf, preIfIndex, sizeof(struct rtmp_adapter *), preIfName); if (new_dev_p == NULL) { /* allocation fail, exit */ DBGPRINT(RT_DEBUG_ERROR, ("Allocate network device fail (CFG80211)...\n")); return; } else { DBGPRINT(RT_DEBUG_TRACE, ("Register CFG80211 I/F (%s)\n", RTMP_OS_NETDEV_GET_DEVNAME(new_dev_p))); } #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,9)) new_dev_p->needs_free_netdev = true; #else new_dev_p->destructor = free_netdev; #endif RTMP_OS_NETDEV_SET_PRIV(new_dev_p, pAd); pNetDevOps->needProtcted = true; memmove(&pNetDevOps->devAddr[0], &pAd->CurrentAddress[0], MAC_ADDR_LEN); //CFG_TODO /* Bit1 of MAC address Byte0 is local administration bit and should be set to 1 in extended multiple BSSIDs' Bit3~ of MAC address Byte0 is extended multiple BSSID index. */ if (pAd->chipCap.MBSSIDMode == MBSSID_MODE1) pNetDevOps->devAddr[0] += 2; /* NEW BSSID */ else { #ifdef P2P_ODD_MAC_ADJUST if (pNetDevOps->devAddr[5] & 0x01 == 0x01) pNetDevOps->devAddr[5] -= 1; else #endif /* P2P_ODD_MAC_ADJUST */ pNetDevOps->devAddr[5] += FIRST_MBSSID; } switch (DevType) { case RT_CMD_80211_IFTYPE_MONITOR: DBGPRINT(RT_DEBUG_ERROR, ("CFG80211 I/F Monitor Type\n")); //RTMP_OS_NETDEV_SET_TYPE_MONITOR(new_dev_p); break; default: DBGPRINT(RT_DEBUG_ERROR, ("Unknown CFG80211 I/F Type (%d)\n", DevType)); } //CFG_TODO : should be move to VIF_CHG if ((DevType == RT_CMD_80211_IFTYPE_P2P_CLIENT) || (DevType == RT_CMD_80211_IFTYPE_P2P_GO)) { COPY_MAC_ADDR(pAd->cfg80211_ctrl.P2PCurrentAddress, pNetDevOps->devAddr); } pWdev = kzalloc(sizeof(*pWdev), GFP_KERNEL); new_dev_p->ieee80211_ptr = pWdev; pWdev->wiphy = p80211CB->pCfg80211_Wdev->wiphy; SET_NETDEV_DEV(new_dev_p, wiphy_dev(pWdev->wiphy)); pWdev->netdev = new_dev_p; pWdev->iftype = DevType; RtmpOSNetDevAttach(pAd->OpMode, new_dev_p, pNetDevOps); AsicSetBssid(pAd, pAd->CurrentAddress); /* Record the pNetDevice to Cfg80211VifDevList */ RTMP_CFG80211_AddVifEntry(pAd, new_dev_p, DevType); DBGPRINT(RT_DEBUG_TRACE, ("%s <---\n", __FUNCTION__)); }
static int __devinit rt2870_probe(IN struct usb_interface *intf, IN struct usb_device *usb_dev, IN const struct usb_device_id *dev_id, struct rt_rtmp_adapter **ppAd) { struct net_device *net_dev = NULL; struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)NULL; int status, rv; void *handle; struct rt_rtmp_os_netdev_op_hook netDevHook; DBGPRINT(RT_DEBUG_TRACE, ("===>rt2870_probe()!\n")); /* Check chipset vendor/product ID */ /*if (RT28XXChipsetCheck(_dev_p) == FALSE) */ /* goto err_out; */ /*RtmpDevInit============================================= */ /* Allocate struct rt_rtmp_adapter adapter structure */ handle = kmalloc(sizeof(struct os_cookie), GFP_KERNEL); if (handle == NULL) { printk ("rt2870_probe(): Allocate memory for os handle failed!\n"); return -ENOMEM; } ((struct os_cookie *)handle)->pUsb_Dev = usb_dev; rv = RTMPAllocAdapterBlock(handle, &pAd); if (rv != NDIS_STATUS_SUCCESS) { kfree(handle); goto err_out; } /*USBDevInit============================================== */ if (USBDevConfigInit(usb_dev, intf, pAd) == FALSE) goto err_out_free_radev; RtmpRaDevCtrlInit(pAd, RTMP_DEV_INF_USB); /*NetDevInit============================================== */ net_dev = RtmpPhyNetDevInit(pAd, &netDevHook); if (net_dev == NULL) goto err_out_free_radev; /* Here are the net_device structure with usb specific parameters. */ /* for supporting Network Manager. * Set the sysfs physical device reference for the network logical device if set prior to registration will * cause a symlink during initialization. */ SET_NETDEV_DEV(net_dev, &(usb_dev->dev)); pAd->StaCfg.OriDevType = net_dev->type; /*All done, it's time to register the net device to linux kernel. */ /* Register this device */ status = RtmpOSNetDevAttach(net_dev, &netDevHook); if (status != 0) goto err_out_free_netdev; #ifdef KTHREAD_SUPPORT init_waitqueue_head(&pAd->mlmeTask.kthread_q); init_waitqueue_head(&pAd->timerTask.kthread_q); init_waitqueue_head(&pAd->cmdQTask.kthread_q); #endif *ppAd = pAd; DBGPRINT(RT_DEBUG_TRACE, ("<===rt2870_probe()!\n")); return 0; /* --------------------------- ERROR HANDLE --------------------------- */ err_out_free_netdev: RtmpOSNetDevFree(net_dev); err_out_free_radev: RTMPFreeAdapter(pAd); err_out: *ppAd = NULL; return -1; }
static int rt2870_probe( IN struct usb_interface *intf, IN struct usb_device *usb_dev, IN const USB_DEVICE_ID *dev_id, IN VOID **ppAd) { struct net_device *net_dev = NULL; VOID *pAd = (VOID *) NULL; INT status, rv; PVOID handle; RTMP_OS_NETDEV_OP_HOOK netDevHook; ULONG OpMode; #ifdef CONFIG_PM #ifdef USB_SUPPORT_SELECTIVE_SUSPEND /* INT pm_usage_cnt; */ INT res =1 ; #endif /* USB_SUPPORT_SELECTIVE_SUSPEND */ #endif /* CONFIG_PM */ DBGPRINT(RT_DEBUG_TRACE, ("===>rt2870_probe()!\n")); #ifdef CONFIG_PM #ifdef USB_SUPPORT_SELECTIVE_SUSPEND res = usb_autopm_get_interface(intf); if (res) { DBGPRINT(RT_DEBUG_ERROR, ("rt2870_probe autopm_resume fail ------\n")); return -EIO; } #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32) atomic_set(&intf->pm_usage_cnt, 1); printk(" rt2870_probe ====> pm_usage_cnt %d \n", atomic_read(&intf->pm_usage_cnt)); #else intf->pm_usage_cnt = 1; printk(" rt2870_probe ====> pm_usage_cnt %d \n", intf->pm_usage_cnt); #endif #endif /* USB_SUPPORT_SELECTIVE_SUSPEND */ #endif /* CONFIG_PM */ /*RtmpDevInit============================================= */ /* Allocate RTMP_ADAPTER adapter structure */ /* handle = kmalloc(sizeof(struct os_cookie), GFP_KERNEL); */ os_alloc_mem(NULL, (UCHAR **)&handle, sizeof(struct os_cookie)); if (handle == NULL) { printk("rt2870_probe(): Allocate memory for os handle failed!\n"); return -ENOMEM; } memset(handle, 0, sizeof(struct os_cookie)); ((POS_COOKIE)handle)->pUsb_Dev = usb_dev; #ifdef CONFIG_PM #ifdef USB_SUPPORT_SELECTIVE_SUSPEND ((POS_COOKIE)handle)->intf = intf; #endif /* USB_SUPPORT_SELECTIVE_SUSPEND */ #endif /* CONFIG_PM */ /* set/get operators to/from DRIVER module */ #ifdef OS_ABL_FUNC_SUPPORT /* get DRIVER operations */ RtmpNetOpsInit(pRtmpDrvNetOps); RTMP_DRV_OPS_FUNCTION(pRtmpDrvOps, pRtmpDrvNetOps, NULL, NULL); RtmpNetOpsSet(pRtmpDrvNetOps); #endif /* OS_ABL_FUNC_SUPPORT */ rv = RTMPAllocAdapterBlock(handle, &pAd); if (rv != NDIS_STATUS_SUCCESS) { /* kfree(handle); */ os_free_mem(NULL, handle); goto err_out; } /*USBDevInit============================================== */ if (USBDevConfigInit(usb_dev, intf, pAd) == FALSE) goto err_out_free_radev; RtmpRaDevCtrlInit(pAd, RTMP_DEV_INF_USB); /*NetDevInit============================================== */ net_dev = RtmpPhyNetDevInit(pAd, &netDevHook); if (net_dev == NULL) goto err_out_free_radev; /* Here are the net_device structure with usb specific parameters. */ #ifdef NATIVE_WPA_SUPPLICANT_SUPPORT /* for supporting Network Manager. * Set the sysfs physical device reference for the network logical device if set prior to registration will * cause a symlink during initialization. */ #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)) SET_NETDEV_DEV(net_dev, &(usb_dev->dev)); #endif #endif /* NATIVE_WPA_SUPPLICANT_SUPPORT */ #ifdef CONFIG_STA_SUPPORT /* pAd->StaCfg.OriDevType = net_dev->type; */ RTMP_DRIVER_STA_DEV_TYPE_SET(pAd, net_dev->type); #endif /* CONFIG_STA_SUPPORT */ /*All done, it's time to register the net device to linux kernel. */ /* Register this device */ #ifdef RT_CFG80211_SUPPORT { /* pAd->pCfgDev = &(usb_dev->dev); */ /* pAd->CFG80211_Register = CFG80211_Register; */ /* RTMP_DRIVER_CFG80211_INIT(pAd, usb_dev); */ /* In 2.6.32, cfg80211 register must be before register_netdevice(); We can not put the register in rt28xx_open(); Or you will suffer NULL pointer in list_add of cfg80211_netdev_notifier_call(). */ CFG80211_Register(pAd, &(usb_dev->dev), net_dev); } #endif /* RT_CFG80211_SUPPORT */ RTMP_DRIVER_OP_MODE_GET(pAd, &OpMode); status = RtmpOSNetDevAttach(OpMode, net_dev, &netDevHook); if (status != 0) goto err_out_free_netdev; /*#ifdef KTHREAD_SUPPORT */ *ppAd = pAd; #ifdef INF_PPA_SUPPORT /* pAd->pDirectpathCb = (PPA_DIRECTPATH_CB *) kmalloc (sizeof(PPA_DIRECTPATH_CB), GFP_ATOMIC); */ /* os_alloc_mem(NULL, (UCHAR **)&(pAd->pDirectpathCb), sizeof(PPA_DIRECTPATH_CB)); */ RTMP_DRIVER_INF_PPA_INIT(pAd); #endif /* INF_PPA_SUPPORT */ #ifdef PRE_ASSIGN_MAC_ADDR UCHAR PermanentAddress[MAC_ADDR_LEN]; RTMP_DRIVER_MAC_ADDR_GET(pAd, &PermanentAddress[0]); DBGPRINT(RT_DEBUG_TRACE, ("@%s MAC address: %02x:%02x:%02x:%02x:%02x:%02x\n", __FUNCTION__, PermanentAddress[0], PermanentAddress[1],PermanentAddress[2],PermanentAddress[3],PermanentAddress[4],PermanentAddress[5])); /* Set up the Mac address */ RtmpOSNetDevAddrSet(OpMode, net_dev, &PermanentAddress[0], NULL); #endif /* PRE_ASSIGN_MAC_ADDR */ #ifdef CONFIG_HAS_EARLYSUSPEND RTMP_DRIVER_ADAPTER_REGISTER_EARLYSUSPEND(pAd); #endif #ifdef EXT_BUILD_CHANNEL_LIST RTMP_DRIVER_SET_PRECONFIG_VALUE(pAd); #endif /* EXT_BUILD_CHANNEL_LIST */ DBGPRINT(RT_DEBUG_TRACE, ("<===rt2870_probe()!\n")); return 0; /* --------------------------- ERROR HANDLE --------------------------- */ err_out_free_netdev: RtmpOSNetDevFree(net_dev); err_out_free_radev: RTMPFreeAdapter(pAd); err_out: *ppAd = NULL; return -1; }
// // PCI device probe & initialization function // static INT __devinit rt2860_probe( IN struct pci_dev *pci_dev, IN const struct pci_device_id *pci_id) { PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)NULL; struct net_device *net_dev; PVOID handle; PSTRING print_name; ULONG csr_addr; INT rv = 0; RTMP_OS_NETDEV_OP_HOOK netDevHook; #ifdef PRE_ASSIGN_MAC_ADDR USHORT Addr01,Addr23,Addr45 ; #endif // PRE_ASSIGN_MAC_ADDR // DBGPRINT(RT_DEBUG_TRACE, ("===> rt2860_probe\n")); //PCIDevInit============================================== // wake up and enable device if ((rv = pci_enable_device(pci_dev))!= 0) { DBGPRINT(RT_DEBUG_ERROR, ("Enable PCI device failed, errno=%d!\n", rv)); return rv; } #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) print_name = pci_dev ? pci_name(pci_dev) : "rt2860"; #else print_name = pci_dev ? pci_dev->slot_name : "rt2860"; #endif // LINUX_VERSION_CODE // if ((rv = pci_request_regions(pci_dev, print_name)) != 0) { DBGPRINT(RT_DEBUG_ERROR, ("Request PCI resource failed, errno=%d!\n", rv)); goto err_out; } // map physical address to virtual address for accessing register csr_addr = (unsigned long) ioremap(pci_resource_start(pci_dev, 0), pci_resource_len(pci_dev, 0)); if (!csr_addr) { DBGPRINT(RT_DEBUG_ERROR, ("ioremap failed for device %s, region 0x%lX @ 0x%lX\n", print_name, (ULONG)pci_resource_len(pci_dev, 0), (ULONG)pci_resource_start(pci_dev, 0))); goto err_out_free_res; } else { DBGPRINT(RT_DEBUG_TRACE, ("%s: at 0x%lx, VA 0x%lx, IRQ %d. \n", print_name, (ULONG)pci_resource_start(pci_dev, 0), (ULONG)csr_addr, pci_dev->irq)); } // Set DMA master pci_set_master(pci_dev); //RtmpDevInit============================================== // Allocate RTMP_ADAPTER adapter structure handle = kmalloc(sizeof(struct os_cookie), GFP_KERNEL); if (handle == NULL) { DBGPRINT(RT_DEBUG_ERROR, ("%s(): Allocate memory for os handle failed!\n", __FUNCTION__)); goto err_out_iounmap; } memset(handle, 0, sizeof(struct os_cookie)); ((POS_COOKIE)handle)->pci_dev = pci_dev; rv = RTMPAllocAdapterBlock(handle, &pAd); //shiang: we may need the pci_dev for allocate structure of "RTMP_ADAPTER" if (rv != NDIS_STATUS_SUCCESS) goto err_out_iounmap; // Here are the RTMP_ADAPTER structure with pci-bus specific parameters. pAd->CSRBaseAddress = (PUCHAR)csr_addr; DBGPRINT(RT_DEBUG_ERROR, ("pAd->CSRBaseAddress =0x%lx, csr_addr=0x%lx!\n", (ULONG)pAd->CSRBaseAddress, csr_addr)); RTMPInitPCIeDevice(pci_dev, pAd); //NetDevInit============================================== net_dev = RtmpPhyNetDevInit(pAd, &netDevHook); if (net_dev == NULL) goto err_out_free_radev; // Here are the net_device structure with pci-bus specific parameters. net_dev->irq = pci_dev->irq; // Interrupt IRQ number net_dev->base_addr = csr_addr; // Save CSR virtual address and irq to device structure pci_set_drvdata(pci_dev, net_dev); // Set driver data #ifdef NATIVE_WPA_SUPPLICANT_SUPPORT /* for supporting Network Manager */ /* Set the sysfs physical device reference for the network logical device * if set prior to registration will cause a symlink during initialization. */ #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)) SET_NETDEV_DEV(net_dev, &(pci_dev->dev)); #endif #endif // NATIVE_WPA_SUPPLICANT_SUPPORT // //All done, it's time to register the net device to linux kernel. // Register this device #ifdef RT_CFG80211_SUPPORT pAd->pCfgDev = &(pci_dev->dev); pAd->CFG80211_Register = CFG80211_Register; #endif // RT_CFG80211_SUPPORT // rv = RtmpOSNetDevAttach(net_dev, &netDevHook); if (rv) goto err_out_free_netdev; #ifdef CONFIG_STA_SUPPORT pAd->StaCfg.OriDevType = net_dev->type; #endif // CONFIG_STA_SUPPORT // #ifdef KTHREAD_SUPPORT init_waitqueue_head(&pAd->cmdQTask.kthread_q); #endif // KTHREAD_SUPPORT // //NICReadEEPROMParameters(pAd, ""); #ifdef CREDENTIAL_STORE NdisAllocateSpinLock(&pAd->StaCtIf.Lock); #endif /* CREDENTIAL_STORE */ #ifdef PRE_ASSIGN_MAC_ADDR RT28xx_EEPROM_READ16(pAd, 0x04, Addr01); RT28xx_EEPROM_READ16(pAd, 0x06, Addr23); RT28xx_EEPROM_READ16(pAd, 0x08, Addr45); pAd->PermanentAddress[0] = (UCHAR)(Addr01 & 0xff); pAd->PermanentAddress[1] = (UCHAR)(Addr01 >> 8); pAd->PermanentAddress[2] = (UCHAR)(Addr23 & 0xff); pAd->PermanentAddress[3] = (UCHAR)(Addr23 >> 8); pAd->PermanentAddress[4] = (UCHAR)(Addr45 & 0xff); pAd->PermanentAddress[5] = (UCHAR)(Addr45 >> 8); // Set up the Mac address RtmpOSNetDevAddrSet(pAd->net_dev, &pAd->PermanentAddress[0]); #endif // PRE_ASSIGN_MAC_ADDR // DBGPRINT(RT_DEBUG_TRACE, ("<=== rt2860_probe\n")); return 0; // probe ok /* --------------------------- ERROR HANDLE --------------------------- */ err_out_free_netdev: RtmpOSNetDevFree(net_dev); err_out_free_radev: /* free RTMP_ADAPTER strcuture and os_cookie*/ RTMPFreeAdapter(pAd); err_out_iounmap: iounmap((void *)(csr_addr)); release_mem_region(pci_resource_start(pci_dev, 0), pci_resource_len(pci_dev, 0)); err_out_free_res: pci_release_regions(pci_dev); err_out: pci_disable_device(pci_dev); DBGPRINT(RT_DEBUG_ERROR, ("<=== rt2860_probe failed with rv = %d!\n", rv)); return -ENODEV; /* probe fail */ }
static int rt2870_probe( IN struct usb_interface *intf, IN struct usb_device *usb_dev, IN const USB_DEVICE_ID *dev_id, IN RTMP_ADAPTER **ppAd) { struct net_device *net_dev = NULL; RTMP_ADAPTER *pAd = (RTMP_ADAPTER *) NULL; INT status, rv; PVOID handle; RTMP_OS_NETDEV_OP_HOOK netDevHook; DBGPRINT(RT_DEBUG_TRACE, ("===>rt2870_probe()!\n")); // Check chipset vendor/product ID //if (RT28XXChipsetCheck(_dev_p) == FALSE) // goto err_out; //RtmpDevInit============================================= // Allocate RTMP_ADAPTER adapter structure handle = kmalloc(sizeof(struct os_cookie), GFP_KERNEL); if (handle == NULL) { printk("rt2870_probe(): Allocate memory for os handle failed!\n"); return -ENOMEM; } ((POS_COOKIE)handle)->pUsb_Dev = usb_dev; rv = RTMPAllocAdapterBlock(handle, &pAd); if (rv != NDIS_STATUS_SUCCESS) { kfree(handle); goto err_out; } //USBDevInit============================================== if (USBDevConfigInit(usb_dev, intf, pAd) == FALSE) goto err_out_free_radev; RtmpRaDevCtrlInit(pAd, RTMP_DEV_INF_USB); //NetDevInit============================================== net_dev = RtmpPhyNetDevInit(pAd, &netDevHook); if (net_dev == NULL) goto err_out_free_radev; // Here are the net_device structure with usb specific parameters. #ifdef NATIVE_WPA_SUPPLICANT_SUPPORT /* for supporting Network Manager. * Set the sysfs physical device reference for the network logical device if set prior to registration will * cause a symlink during initialization. */ #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)) SET_NETDEV_DEV(net_dev, &(usb_dev->dev)); #endif #endif // NATIVE_WPA_SUPPLICANT_SUPPORT // #ifdef CONFIG_STA_SUPPORT pAd->StaCfg.OriDevType = net_dev->type; #endif // CONFIG_STA_SUPPORT // //All done, it's time to register the net device to linux kernel. // Register this device status = RtmpOSNetDevAttach(net_dev, &netDevHook); if (status != 0) goto err_out_free_netdev; #ifdef KTHREAD_SUPPORT init_waitqueue_head(&pAd->mlmeTask.kthread_q); init_waitqueue_head(&pAd->timerTask.kthread_q); init_waitqueue_head(&pAd->cmdQTask.kthread_q); #endif #ifdef RT_CFG80211_SUPPORT pAd->pCfgDev = &(usb_dev->dev); #endif // RT_CFG80211_SUPPORT // *ppAd = pAd; #ifdef INF_AMAZON_PPA pAd->pDirectpathCb = (PPA_DIRECTPATH_CB *) kmalloc (sizeof(PPA_DIRECTPATH_CB), GFP_ATOMIC); #endif // INF_AMAZON_PPA // DBGPRINT(RT_DEBUG_TRACE, ("<===rt2870_probe()!\n")); return 0; /* --------------------------- ERROR HANDLE --------------------------- */ err_out_free_netdev: RtmpOSNetDevFree(net_dev); err_out_free_radev: RTMPFreeAdapter(pAd); err_out: *ppAd = NULL; return -1; }
VOID RTMP_CFG80211_DummyP2pIf_Init( IN VOID *pAdSrc) { #define INF_CFG80211_DUMMY_P2P_NAME "p2p" PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)pAdSrc; CFG80211_CB *p80211CB = pAd->pCfg80211_CB; PCFG80211_CTRL cfg80211_ctrl = &pAd->cfg80211_ctrl; RTMP_OS_NETDEV_OP_HOOK netDevHook, *pNetDevOps; PNET_DEV new_dev_p; UINT32 MC_RowID = 0, IoctlIF = 0, Inf = INT_P2P; UINT preIfIndex = 0; struct wireless_dev *pWdev; DBGPRINT(RT_DEBUG_TRACE, (" %s =====> \n", __FUNCTION__)); if (cfg80211_ctrl->flg_cfg_dummy_p2p_init != FALSE) return; #if RT_CFG80211_P2P_SUPPORT cfg80211_ctrl->bP2pCliPmEnable = FALSE; cfg80211_ctrl->bPreKeepSlient = FALSE; cfg80211_ctrl->bKeepSlient = FALSE; cfg80211_ctrl->NoAIndex = MAX_LEN_OF_MAC_TABLE; cfg80211_ctrl->MyGOwcid = MAX_LEN_OF_MAC_TABLE; cfg80211_ctrl->CTWindows=0; /* CTWindows and OppPS parameter field */ #endif /* RT_CFG80211_P2P_SUPPORT */ pNetDevOps=&netDevHook; /* init operation functions and flags */ NdisZeroMemory(&netDevHook, sizeof(netDevHook)); netDevHook.open = CFG80211_DummyP2pIf_Open; /* device opem hook point */ netDevHook.stop = CFG80211_DummyP2pIf_Close; /* device close hook point */ netDevHook.xmit = CFG80211_DummyP2pIf_PacketSend; /* hard transmit hook point */ netDevHook.ioctl = CFG80211_DummyP2pIf_Ioctl; /* ioctl hook point */ new_dev_p = RtmpOSNetDevCreate(MC_RowID, &IoctlIF, Inf, preIfIndex, sizeof(PRTMP_ADAPTER), INF_CFG80211_DUMMY_P2P_NAME); if (new_dev_p == NULL) { /* allocation fail, exit */ DBGPRINT(RT_DEBUG_ERROR, ("Allocate network device fail (CFG80211: Dummy P2P IF)...\n")); return; } else { DBGPRINT(RT_DEBUG_TRACE, ("Register CFG80211 I/F (%s)\n", RTMP_OS_NETDEV_GET_DEVNAME(new_dev_p))); } RTMP_OS_NETDEV_SET_PRIV(new_dev_p, pAd); NdisMoveMemory(&pNetDevOps->devAddr[0], &pAd->CurrentAddress[0], MAC_ADDR_LEN); pNetDevOps->needProtcted = TRUE; pWdev = kzalloc(sizeof(*pWdev), GFP_KERNEL); if (unlikely(!pWdev)) { DBGPRINT(RT_DEBUG_ERROR, ("Could not allocate wireless device\n")); return; } new_dev_p->ieee80211_ptr = pWdev; pWdev->wiphy = p80211CB->pCfg80211_Wdev->wiphy; SET_NETDEV_DEV(new_dev_p, wiphy_dev(pWdev->wiphy)); pWdev->netdev = new_dev_p; pWdev->iftype = RT_CMD_80211_IFTYPE_STATION; RtmpOSNetDevAttach(pAd->OpMode, new_dev_p, pNetDevOps); cfg80211_ctrl->dummy_p2p_net_dev = new_dev_p; cfg80211_ctrl->flg_cfg_dummy_p2p_init = TRUE; DBGPRINT(RT_DEBUG_TRACE, (" %s <=====\n", __FUNCTION__)); }
static INT __devinit rt2860_probe( IN struct pci_dev *pci_dev, IN const struct pci_device_id *pci_id) { VOID *pAd = NULL; struct net_device *net_dev; PVOID handle; PSTRING print_name; ULONG csr_addr; INT rv = 0; RTMP_OS_NETDEV_OP_HOOK netDevHook; ULONG OpMode; DBGPRINT(RT_DEBUG_TRACE, ("===> rt2860_probe\n")); /*PCIDevInit============================================== */ /* wake up and enable device */ if ((rv = pci_enable_device(pci_dev))!= 0) { DBGPRINT(RT_DEBUG_ERROR, ("Enable PCI device failed, errno=%d!\n", rv)); return rv; } #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) print_name = pci_name(pci_dev); #else print_name = pci_dev->slot_name; #endif /* LINUX_VERSION_CODE */ if ((rv = pci_request_regions(pci_dev, print_name)) != 0) { DBGPRINT(RT_DEBUG_ERROR, ("Request PCI resource failed, errno=%d!\n", rv)); goto err_out; } /* map physical address to virtual address for accessing register */ csr_addr = (unsigned long) ioremap(pci_resource_start(pci_dev, 0), pci_resource_len(pci_dev, 0)); if (!csr_addr) { DBGPRINT(RT_DEBUG_ERROR, ("ioremap failed for device %s, region 0x%lX @ 0x%lX\n", print_name, (ULONG)pci_resource_len(pci_dev, 0), (ULONG)pci_resource_start(pci_dev, 0))); goto err_out_free_res; } else { DBGPRINT(RT_DEBUG_TRACE, ("%s: at 0x%lx, VA 0x%lx, IRQ %d. \n", print_name, (ULONG)pci_resource_start(pci_dev, 0), (ULONG)csr_addr, pci_dev->irq)); } /* Set DMA master */ pci_set_master(pci_dev); /*RtmpDevInit============================================== */ /* Allocate RTMP_ADAPTER adapter structure */ /* handle = kmalloc(sizeof(struct os_cookie), GFP_KERNEL); */ os_alloc_mem(NULL, (UCHAR **)&handle, sizeof(struct os_cookie)); if (handle == NULL) { DBGPRINT(RT_DEBUG_ERROR, ("%s(): Allocate memory for os handle failed!\n", __FUNCTION__)); goto err_out_iounmap; } memset(handle, 0, sizeof(struct os_cookie)); ((POS_COOKIE)handle)->pci_dev = pci_dev; #ifdef OS_ABL_FUNC_SUPPORT { RTMP_PCI_CONFIG PciConfig; PciConfig.ConfigVendorID = PCI_VENDOR_ID; /* get DRIVER operations */ RTMP_DRV_OPS_FUNCTION(pRtmpDrvOps, NULL, &PciConfig, NULL); } #endif /* OS_ABL_FUNC_SUPPORT */ rv = RTMPAllocAdapterBlock(handle, &pAd); /* we may need the pci_dev for allocate structure of "RTMP_ADAPTER" */ if (rv != NDIS_STATUS_SUCCESS) goto err_out_iounmap; /* Here are the RTMP_ADAPTER structure with pci-bus specific parameters. */ /* pAd->CSRBaseAddress = (PUCHAR)csr_addr; */ RTMP_DRIVER_PCI_CSR_SET(pAd, csr_addr); /* RTMPInitPCIeDevice(pci_dev, pAd); */ RTMP_DRIVER_PCIE_INIT(pAd, pci_dev); /*NetDevInit============================================== */ net_dev = RtmpPhyNetDevInit(pAd, &netDevHook); if (net_dev == NULL) goto err_out_free_radev; /* Here are the net_device structure with pci-bus specific parameters. */ net_dev->irq = pci_dev->irq; /* Interrupt IRQ number */ net_dev->base_addr = csr_addr; /* Save CSR virtual address and irq to device structure */ pci_set_drvdata(pci_dev, net_dev); /* Set driver data */ #ifdef NATIVE_WPA_SUPPLICANT_SUPPORT /* for supporting Network Manager */ /* Set the sysfs physical device reference for the network logical device * if set prior to registration will cause a symlink during initialization. */ #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)) SET_NETDEV_DEV(net_dev, &(pci_dev->dev)); #endif #endif /* NATIVE_WPA_SUPPLICANT_SUPPORT */ /*All done, it's time to register the net device to linux kernel. */ /* Register this device */ #ifdef RT_CFG80211_SUPPORT { /* pAd->pCfgDev = &(pci_dev->dev); */ /* pAd->CFG80211_Register = CFG80211_Register; */ /* RTMP_DRIVER_CFG80211_INIT(pAd, pci_dev); */ /* In 2.6.32, cfg80211 register must be before register_netdevice(); We can not put the register in rt28xx_open(); Or you will suffer NULL pointer in list_add of cfg80211_netdev_notifier_call(). */ CFG80211_Register(pAd, &(pci_dev->dev), net_dev); } #endif /* RT_CFG80211_SUPPORT */ RTMP_DRIVER_OP_MODE_GET(pAd, &OpMode); rv = RtmpOSNetDevAttach(OpMode, net_dev, &netDevHook); if (rv) goto err_out_free_netdev; #ifdef CONFIG_STA_SUPPORT /* pAd->StaCfg.OriDevType = net_dev->type; */ RTMP_DRIVER_STA_DEV_TYPE_SET(pAd, net_dev->type); #endif /* CONFIG_STA_SUPPORT */ /*#ifdef KTHREAD_SUPPORT */ #ifdef PRE_ASSIGN_MAC_ADDR UCHAR PermanentAddress[MAC_ADDR_LEN]; RTMP_DRIVER_MAC_ADDR_GET(pAd, &PermanentAddress[0]); DBGPRINT(RT_DEBUG_TRACE, ("@%s MAC address: %02x:%02x:%02x:%02x:%02x:%02x\n", __FUNCTION__, PermanentAddress[0], PermanentAddress[1],PermanentAddress[2],PermanentAddress[3],PermanentAddress[4],PermanentAddress[5])); /* Set up the Mac address */ RtmpOSNetDevAddrSet(OpMode, net_dev, &PermanentAddress[0], NULL); #endif /* PRE_ASSIGN_MAC_ADDR */ DBGPRINT(RT_DEBUG_TRACE, ("<=== rt2860_probe\n")); return 0; /* probe ok */ /* --------------------------- ERROR HANDLE --------------------------- */ err_out_free_netdev: RtmpOSNetDevFree(net_dev); err_out_free_radev: /* free RTMP_ADAPTER strcuture and os_cookie*/ RTMPFreeAdapter(pAd); err_out_iounmap: iounmap((void *)(csr_addr)); release_mem_region(pci_resource_start(pci_dev, 0), pci_resource_len(pci_dev, 0)); err_out_free_res: pci_release_regions(pci_dev); err_out: pci_disable_device(pci_dev); DBGPRINT(RT_DEBUG_ERROR, ("<=== rt2860_probe failed with rv = %d!\n", rv)); return -ENODEV; /* probe fail */ }
static int rt2870_probe( struct usb_interface *intf, struct usb_device *usb_dev, const USB_DEVICE_ID *dev_id, VOID **ppAd) { struct net_device *net_dev = NULL; #ifdef RESUME_WITH_USB_RESET_SUPPORT VOID *pAd = (VOID *) gpAd; #else VOID *pAd = (VOID *) NULL; #endif /* RESUME_WITH_USB_RESET_SUPPORT */ INT status, rv; PVOID handle; RTMP_OS_NETDEV_OP_HOOK netDevHook; ULONG OpMode; #ifdef CONFIG_PM #ifdef USB_SUPPORT_SELECTIVE_SUSPEND /* INT pm_usage_cnt; */ INT res =1 ; #endif /* USB_SUPPORT_SELECTIVE_SUSPEND */ #endif /* CONFIG_PM */ DBGPRINT(RT_DEBUG_TRACE, ("===>rt2870_probe()!\n")); #ifdef CONFIG_PM #ifdef USB_SUPPORT_SELECTIVE_SUSPEND res = usb_autopm_get_interface(intf); if (res) { DBGPRINT(RT_DEBUG_ERROR, ("rt2870_probe autopm_resume fail ------\n")); return -EIO; } #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32) atomic_set(&intf->pm_usage_cnt, 1); printk(" rt2870_probe ====> pm_usage_cnt %d \n", atomic_read(&intf->pm_usage_cnt)); #else intf->pm_usage_cnt = 1; printk(" rt2870_probe ====> pm_usage_cnt %d \n", intf->pm_usage_cnt); #endif #endif /* USB_SUPPORT_SELECTIVE_SUSPEND */ #endif /* CONFIG_PM */ os_alloc_mem(NULL, (UCHAR **)&handle, sizeof(struct os_cookie)); if (handle == NULL) { printk("rt2870_probe(): Allocate memory for os handle failed!\n"); return -ENOMEM; } memset(handle, 0, sizeof(struct os_cookie)); ((POS_COOKIE)handle)->pUsb_Dev = usb_dev; #ifdef CONFIG_PM #ifdef USB_SUPPORT_SELECTIVE_SUSPEND ((POS_COOKIE)handle)->intf = intf; #endif /* USB_SUPPORT_SELECTIVE_SUSPEND */ #endif /* CONFIG_PM */ /* set/get operators to/from DRIVER module */ #ifdef OS_ABL_FUNC_SUPPORT /* get DRIVER operations */ RtmpNetOpsInit(pRtmpDrvNetOps); RTMP_DRV_OPS_FUNCTION(pRtmpDrvOps, pRtmpDrvNetOps, NULL, NULL); RtmpNetOpsSet(pRtmpDrvNetOps); #endif /* OS_ABL_FUNC_SUPPORT */ #ifdef RESUME_WITH_USB_RESET_SUPPORT if (rtusb_fast_probe(handle, &pAd, intf) == NDIS_STATUS_SUCCESS) { *ppAd = pAd; goto fast_probe_done; } #endif /* RESUME_WITH_USB_RESET_SUPPORT */ rv = RTMPAllocAdapterBlock(handle, &pAd); if (rv != NDIS_STATUS_SUCCESS) { os_free_mem(NULL, handle); goto err_out; } if (USBDevConfigInit(usb_dev, intf, pAd) == FALSE) goto err_out_free_radev; RTMP_DRIVER_USB_INIT(pAd, usb_dev, dev_id->driver_info); net_dev = RtmpPhyNetDevInit(pAd, &netDevHook); if (net_dev == NULL) goto err_out_free_radev; /* Here are the net_device structure with usb specific parameters. */ #ifdef NATIVE_WPA_SUPPLICANT_SUPPORT /* for supporting Network Manager. * Set the sysfs physical device reference for the network logical device if set prior to registration will * cause a symlink during initialization. */ #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)) SET_NETDEV_DEV(net_dev, &(usb_dev->dev)); #endif #endif /* NATIVE_WPA_SUPPLICANT_SUPPORT */ #ifdef CONFIG_STA_SUPPORT /* pAd->StaCfg.OriDevType = net_dev->type; */ RTMP_DRIVER_STA_DEV_TYPE_SET(pAd, net_dev->type); #ifdef PROFILE_PATH_DYNAMIC RTMP_DRIVER_STA_PROFILEPATH_SET(pAd, (ULONG)profilePath); #endif /* PROFILE_PATH_DYNAMIC */ #endif /* CONFIG_STA_SUPPORT */ /*All done, it's time to register the net device to linux kernel. */ /* Register this device */ #ifdef RT_CFG80211_SUPPORT { /* pAd->pCfgDev = &(usb_dev->dev); */ /* pAd->CFG80211_Register = CFG80211_Register; */ /* RTMP_DRIVER_CFG80211_INIT(pAd, usb_dev); */ /* In 2.6.32, cfg80211 register must be before register_netdevice(); We can not put the register in rt28xx_open(); Or you will suffer NULL pointer in list_add of cfg80211_netdev_notifier_call(). */ CFG80211_Register(pAd, &(usb_dev->dev), net_dev); } #endif /* RT_CFG80211_SUPPORT */ RTMP_DRIVER_OP_MODE_GET(pAd, &OpMode); status = RtmpOSNetDevAttach(OpMode, net_dev, &netDevHook); if (status != 0) goto err_out_free_netdev; /*#ifdef KTHREAD_SUPPORT */ #if 0 /* move to RtmpOSTaskInit() */ { RT_CMD_WAIT_QUEUE_LIST List, *pList = &List; RTMP_DRIVER_TASK_LIST_GET(pAd, &List); init_waitqueue_head(&(RTMP_OS_TASK_GET(pList->pMlmeTask)->kthread_q)); #ifdef RTMP_TIMER_TASK_SUPPORT init_waitqueue_head(&(RTMP_OS_TASK_GET(pList->pTimerTask)->kthread_q)); #endif /* RTMP_TIMER_TASK_SUPPORT */ init_waitqueue_head(&(RTMP_OS_TASK_GET(pList->pCmdQTask)->kthread_q)); #ifdef WSC_INCLUDED init_waitqueue_head(&(RTMP_OS_TASK_GET(pList->pWscTask)->kthread_q)); #endif /* WSC_INCLUDED */ } #endif /* KTHREAD_SUPPORT */ *ppAd = pAd; #ifdef RESUME_WITH_USB_RESET_SUPPORT gpAd = pAd; #endif /* RESUME_WITH_USB_RESET_SUPPORT */ #ifdef INF_PPA_SUPPORT RTMP_DRIVER_INF_PPA_INIT(pAd); #endif /* INF_PPA_SUPPORT */ #ifdef PRE_ASSIGN_MAC_ADDR { UCHAR PermanentAddress[MAC_ADDR_LEN]; RTMP_DRIVER_MAC_ADDR_GET(pAd, &PermanentAddress[0]); DBGPRINT(RT_DEBUG_TRACE, ("%s():MAC Addr - %02x:%02x:%02x:%02x:%02x:%02x\n", __FUNCTION__, PermanentAddress[0], PermanentAddress[1], PermanentAddress[2],PermanentAddress[3], PermanentAddress[4],PermanentAddress[5])); /* Set up the Mac address */ RtmpOSNetDevAddrSet(OpMode, net_dev, &PermanentAddress[0], NULL); } #endif /* PRE_ASSIGN_MAC_ADDR */ #ifdef EXT_BUILD_CHANNEL_LIST RTMP_DRIVER_SET_PRECONFIG_VALUE(pAd); #endif /* EXT_BUILD_CHANNEL_LIST */ DBGPRINT(RT_DEBUG_TRACE, ("<===rt2870_probe()!\n")); return 0; /* --------------------------- ERROR HANDLE --------------------------- */ err_out_free_netdev: RtmpOSNetDevFree(net_dev); err_out_free_radev: RTMPFreeAdapter(pAd); err_out: *ppAd = NULL; return -1; #ifdef RESUME_WITH_USB_RESET_SUPPORT fast_probe_done: printk("fast probe done\n"); return 0; #endif /* RESUME_WITH_USB_RESET_SUPPORT */ }
VOID WDS_Init(RTMP_ADAPTER *pAd, RTMP_OS_NETDEV_OP_HOOK *pNetDevOps) { INT index; PNET_DEV pWdsNetDev; /* sanity check to avoid redundant virtual interfaces are created */ if (pAd->flg_wds_init != FALSE) return; for(index = 0; index < MAX_WDS_ENTRY; index++) { UINT32 MC_RowID = 0, IoctlIF = 0; RT_802_11_WDS_ENTRY *wds_entry; struct wifi_dev *wdev; char *dev_name; #ifdef MULTIPLE_CARD_SUPPORT MC_RowID = pAd->MC_RowID; #endif /* MULTIPLE_CARD_SUPPORT */ #ifdef HOSTAPD_SUPPORT IoctlIF = pAd->IoctlIF; #endif /* HOSTAPD_SUPPORT */ dev_name = get_dev_name_prefix(pAd, INT_WDS); pWdsNetDev = RtmpOSNetDevCreate(MC_RowID, &IoctlIF, INT_WDS, index, sizeof(struct mt_dev_priv), dev_name); #ifdef HOSTAPD_SUPPORT pAd->IoctlIF = IoctlIF; #endif /* HOSTAPD_SUPPORT */ wds_entry = &pAd->WdsTab.WdsEntry[index]; wdev = &wds_entry->wdev; if (pWdsNetDev == NULL) { /* allocation fail, exit */ DBGPRINT(RT_DEBUG_ERROR, ("Allocate network device fail (WDS)...\n")); break; } DBGPRINT(RT_DEBUG_TRACE, ("The new WDS interface MAC = %02X:%02X:%02X:%02X:%02X:%02X\n", PRINT_MAC(pAd->MacTab.Content[wds_entry->MacTabMatchWCID].Addr))); NdisZeroMemory(&wds_entry->WdsCounter, sizeof(WDS_COUNTER)); wdev->wdev_type = WDEV_TYPE_WDS; wdev->func_dev = wds_entry; wdev->func_idx = index; wdev->sys_handle = (void *)pAd; wdev->if_dev = pWdsNetDev; wdev->tx_pkt_allowed = ApWdsAllowToSendPacket; // TODO: shiang-usw, modify this to WDSSendPacket wdev->tx_pkt_handle = APSendPacket; wdev->wdev_hard_tx = APHardTransmit; wdev->rx_pkt_allowed = ap_rx_pkt_allow; wdev->rx_pkt_foward = wds_rx_foward_handle; wdev->PhyMode = 0xff; wdev->allow_data_tx = TRUE; // let tx_pkt_allowed() to check it! wdev->PortSecured = WPA_802_1X_PORT_SECURED; NdisMoveMemory(&wdev->if_addr[0], &pNetDevOps->devAddr[0], MAC_ADDR_LEN); RTMP_OS_NETDEV_SET_PRIV(pWdsNetDev, pAd); RTMP_OS_NETDEV_SET_WDEV(pWdsNetDev, wdev); if (rtmp_wdev_idx_reg(pAd, wdev) < 0) { DBGPRINT(RT_DEBUG_ERROR, ("Assign wdev idx for %s failed, free net device!\n", RTMP_OS_NETDEV_GET_DEVNAME(pWdsNetDev))); RtmpOSNetDevFree(pWdsNetDev); break; } pNetDevOps->priv_flags = INT_WDS; pNetDevOps->needProtcted = TRUE; pNetDevOps->wdev = wdev; /* Register this device */ RtmpOSNetDevAttach(pAd->OpMode, pWdsNetDev, pNetDevOps); } if (index > 0) pAd->flg_wds_init = TRUE; NdisAllocateSpinLock(pAd, &pAd->WdsTabLock); DBGPRINT(RT_DEBUG_TRACE, ("Total allocated %d WDS interfaces!\n", index)); }
VOID RTMP_CFG80211_VirtualIF_Init( IN VOID *pAdSrc, IN CHAR *pDevName, IN UINT32 DevType) { #ifdef RT_CFG80211_P2P_STATIC_CONCURRENT_DEVICE return; #endif /* RT_CFG80211_P2P_STATIC_CONCURRENT_DEVICE */ PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)pAdSrc; RTMP_OS_NETDEV_OP_HOOK netDevHook, *pNetDevOps; PNET_DEV new_dev_p; APCLI_STRUCT *pApCliEntry; struct wifi_dev *wdev; #ifdef RT_CFG80211_P2P_SUPPORT UINT apidx = CFG_GO_BSSID_IDX; #else UINT apidx = MAIN_MBSSID; #endif /*RT_CFG80211_P2P_SUPPORT*/ CHAR tr_tb_idx = MAX_LEN_OF_MAC_TABLE + apidx; CHAR preIfName[12]; UINT devNameLen = strlen(pDevName); UINT preIfIndex = pDevName[devNameLen-1] - 48; CFG80211_CB *p80211CB = pAd->pCfg80211_CB; struct wireless_dev *pWdev; UINT32 MC_RowID = 0, IoctlIF = 0, Inf = INT_P2P; memset(preIfName, 0, sizeof(preIfName)); NdisCopyMemory(preIfName, pDevName, devNameLen-1); pNetDevOps=&netDevHook; DBGPRINT(RT_DEBUG_TRACE, ("%s ---> (%s, %s, %d)\n", __FUNCTION__, pDevName, preIfName, preIfIndex)); /* init operation functions and flags */ NdisZeroMemory(&netDevHook, sizeof(netDevHook)); netDevHook.open = CFG80211_VirtualIF_Open; /* device opem hook point */ netDevHook.stop = CFG80211_VirtualIF_Close; /* device close hook point */ netDevHook.xmit = CFG80211_VirtualIF_PacketSend; /* hard transmit hook point */ netDevHook.ioctl = CFG80211_VirtualIF_Ioctl; /* ioctl hook point */ #if WIRELESS_EXT >= 12 //netDevHook.iw_handler = (void *)&rt28xx_ap_iw_handler_def; #endif /* WIRELESS_EXT >= 12 */ new_dev_p = RtmpOSNetDevCreate(MC_RowID, &IoctlIF, Inf, preIfIndex, sizeof(PRTMP_ADAPTER), preIfName); if (new_dev_p == NULL) { /* allocation fail, exit */ DBGPRINT(RT_DEBUG_ERROR, ("Allocate network device fail (CFG80211)...\n")); return; } else { DBGPRINT(RT_DEBUG_TRACE, ("Register CFG80211 I/F (%s)\n", RTMP_OS_NETDEV_GET_DEVNAME(new_dev_p))); } new_dev_p->destructor = free_netdev; RTMP_OS_NETDEV_SET_PRIV(new_dev_p, pAd); pNetDevOps->needProtcted = TRUE; NdisMoveMemory(&pNetDevOps->devAddr[0], &pAd->CurrentAddress[0], MAC_ADDR_LEN); #ifdef MT_MAC INT32 Value; UCHAR MacByte = 0; //TODO: shall we make choosing which byte to be selectable??? Value = 0x00000000L; RTMP_IO_READ32(pAd, LPON_BTEIR, &Value);//read BTEIR bit[31:29] for determine to choose which byte to extend BSSID mac address. Value = Value | (0x2 << 29);//Note: Carter, make default will use byte4 bit[31:28] to extend Mac Address RTMP_IO_WRITE32(pAd, LPON_BTEIR, Value); MacByte = Value >> 29; pNetDevOps->devAddr[0] |= 0x2; switch (MacByte) { case 0x1: /* choose bit[23:20]*/ pNetDevOps->devAddr[2] = (pNetDevOps->devAddr[2] = pNetDevOps->devAddr[2] & 0x0f); break; case 0x2: /* choose bit[31:28]*/ pNetDevOps->devAddr[3] = (pNetDevOps->devAddr[3] = pNetDevOps->devAddr[3] & 0x0f); break; case 0x3: /* choose bit[39:36]*/ pNetDevOps->devAddr[4] = (pNetDevOps->devAddr[4] = pNetDevOps->devAddr[4] & 0x0f); break; case 0x4: /* choose bit [47:44]*/ pNetDevOps->devAddr[5] = (pNetDevOps->devAddr[5] = pNetDevOps->devAddr[5] & 0x0f); break; default: /* choose bit[15:12]*/ pNetDevOps->devAddr[1] = (pNetDevOps->devAddr[1] = pNetDevOps->devAddr[1] & 0x0f); break; } AsicSetDevMac(pAd, pNetDevOps->devAddr, 0x1);//set own_mac to HWBSSID1 #else //CFG_TODO /* Bit1 of MAC address Byte0 is local administration bit and should be set to 1 in extended multiple BSSIDs' Bit3~ of MAC address Byte0 is extended multiple BSSID index. */ if (pAd->chipCap.MBSSIDMode == MBSSID_MODE1) pNetDevOps->devAddr[0] += 2; /* NEW BSSID */ else { #ifdef P2P_ODD_MAC_ADJUST if (pNetDevOps->devAddr[5] & 0x01 == 0x01) pNetDevOps->devAddr[5] -= 1; else #endif /* P2P_ODD_MAC_ADJUST */ pNetDevOps->devAddr[5] += FIRST_MBSSID; } #endif /* MT_MAC */ switch (DevType) { #ifdef CONFIG_STA_SUPPORT case RT_CMD_80211_IFTYPE_MONITOR: DBGPRINT(RT_DEBUG_TRACE, ("CFG80211 I/F Monitor Type\n")); //RTMP_OS_NETDEV_SET_TYPE_MONITOR(new_dev_p); break; case RT_CMD_80211_IFTYPE_P2P_CLIENT: case RT_CMD_80211_IFTYPE_STATION: pApCliEntry = &pAd->ApCfg.ApCliTab[MAIN_MBSSID]; wdev = &pApCliEntry->wdev; wdev->wdev_type = WDEV_TYPE_STA; wdev->func_dev = pApCliEntry; wdev->func_idx = MAIN_MBSSID; wdev->sys_handle = (void *)pAd; wdev->if_dev = new_dev_p; /* TX */ wdev->tx_pkt_allowed = ApCliAllowToSendPacket; wdev->wdev_hard_tx = APHardTransmit; wdev->tx_pkt_handle = APSendPacket; /* RX */ wdev->rx_pkt_allowed = sta_rx_pkt_allow; wdev->rx_pkt_foward = sta_rx_fwd_hnd; RTMP_OS_NETDEV_SET_PRIV(new_dev_p, pAd); RTMP_OS_NETDEV_SET_WDEV(new_dev_p, wdev); if (rtmp_wdev_idx_reg(pAd, wdev) < 0) { DBGPRINT(RT_DEBUG_ERROR, ("%s: Assign wdev idx for %s failed, free net device!\n", __FUNCTION__,RTMP_OS_NETDEV_GET_DEVNAME(new_dev_p))); RtmpOSNetDevFree(new_dev_p); break; } /* init MAC address of virtual network interface */ COPY_MAC_ADDR(wdev->if_addr, pNetDevOps->devAddr); break; #endif /*CONFIG_STA_SUPPORT*/ case RT_CMD_80211_IFTYPE_P2P_GO: /* Only ForceGO init from here, Nego as GO init on AddBeacon Ops. */ pNetDevOps->priv_flags = INT_P2P; /* The Behivaor in SetBeacon Ops */ pAd->cfg80211_ctrl.isCfgInApMode = RT_CMD_80211_IFTYPE_AP; wdev = &pAd->ApCfg.MBSSID[apidx].wdev; wdev->wdev_type = WDEV_TYPE_AP; wdev->func_dev = &pAd->ApCfg.MBSSID[apidx]; wdev->func_idx = apidx; wdev->sys_handle = (void *)pAd; wdev->if_dev = new_dev_p; /* BC/MC Handling */ wdev->tr_tb_idx = tr_tb_idx; tr_tb_set_mcast_entry(pAd, tr_tb_idx, wdev); /* TX */ wdev->tx_pkt_allowed = ApAllowToSendPacket; wdev->wdev_hard_tx = APHardTransmit; wdev->tx_pkt_handle = APSendPacket; /* RX */ wdev->rx_pkt_allowed = ap_rx_pkt_allow; wdev->rx_pkt_foward = ap_rx_foward_handle; wdev->rx_ps_handle = ap_rx_ps_handle; /* for concurrent purpose */ wdev->hw_bssid_idx = CFG_GO_BSSID_IDX; wdev_bcn_buf_init(pAd, &pAd->ApCfg.MBSSID[apidx].bcn_buf); RTMP_OS_NETDEV_SET_PRIV(new_dev_p, pAd); RTMP_OS_NETDEV_SET_WDEV(new_dev_p, wdev); if (rtmp_wdev_idx_reg(pAd, wdev) < 0) { DBGPRINT(RT_DEBUG_ERROR, ("%s: Assign wdev idx for %s failed, free net device!\n", __FUNCTION__,RTMP_OS_NETDEV_GET_DEVNAME(new_dev_p))); RtmpOSNetDevFree(new_dev_p); break; } COPY_MAC_ADDR(pAd->ApCfg.MBSSID[apidx].wdev.if_addr, pNetDevOps->devAddr); COPY_MAC_ADDR(pAd->ApCfg.MBSSID[apidx].wdev.bssid, pNetDevOps->devAddr); break; default: DBGPRINT(RT_DEBUG_ERROR, ("Unknown CFG80211 I/F Type (%d)\n", DevType)); } //CFG_TODO : should be move to VIF_CHG if ((DevType == RT_CMD_80211_IFTYPE_P2P_CLIENT) || (DevType == RT_CMD_80211_IFTYPE_P2P_GO)) { COPY_MAC_ADDR(pAd->cfg80211_ctrl.P2PCurrentAddress, pNetDevOps->devAddr); } pWdev = kzalloc(sizeof(*pWdev), GFP_KERNEL); new_dev_p->ieee80211_ptr = pWdev; pWdev->wiphy = p80211CB->pCfg80211_Wdev->wiphy; SET_NETDEV_DEV(new_dev_p, wiphy_dev(pWdev->wiphy)); pWdev->netdev = new_dev_p; pWdev->iftype = DevType; #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)) COPY_MAC_ADDR(pWdev->address, pNetDevOps->devAddr); #endif /* LINUX_VERSION_CODE: 3.7.0 */ RtmpOSNetDevAttach(pAd->OpMode, new_dev_p, pNetDevOps); //AsicSetBssid(pAd, pAd->CurrentAddress, 0x0); //AsicSetBssid(pAd, wdev->if_addr, 0x1); /* Record the pNetDevice to Cfg80211VifDevList */ RTMP_CFG80211_AddVifEntry(pAd, new_dev_p, DevType); DBGPRINT(RT_DEBUG_TRACE, ("%s <---\n", __FUNCTION__)); }
VOID RTMP_CFG80211_DummyP2pIf_Init( IN struct rtmp_adapter *pAd) { #define INF_CFG80211_DUMMY_P2P_NAME "p2p" struct mt7612u_cfg80211_cb *p80211CB = pAd->pCfg80211_CB; PCFG80211_CTRL cfg80211_ctrl = &pAd->cfg80211_ctrl; struct RTMP_OS_NETDEV_OP_HOOK netDevHook, *pNetDevOps; struct net_device *new_dev_p; uint32_t MC_RowID = 0, IoctlIF = 0, Inf = INT_P2P; UINT preIfIndex = 0; struct wireless_dev *pWdev; DBGPRINT(RT_DEBUG_TRACE, (" %s =====> \n", __FUNCTION__)); if (cfg80211_ctrl->flg_cfg_dummy_p2p_init != false) return; pNetDevOps=&netDevHook; /* init operation functions and flags */ memset(&netDevHook, 0, sizeof(netDevHook)); netDevHook.open = CFG80211_DummyP2pIf_Open; /* device opem hook point */ netDevHook.stop = CFG80211_DummyP2pIf_Close; /* device close hook point */ netDevHook.xmit = CFG80211_DummyP2pIf_PacketSend; /* hard transmit hook point */ netDevHook.ioctl = CFG80211_DummyP2pIf_Ioctl; /* ioctl hook point */ new_dev_p = RtmpOSNetDevCreate(MC_RowID, &IoctlIF, Inf, preIfIndex, sizeof(struct rtmp_adapter *), INF_CFG80211_DUMMY_P2P_NAME); if (new_dev_p == NULL) { /* allocation fail, exit */ DBGPRINT(RT_DEBUG_ERROR, ("Allocate network device fail (CFG80211: Dummy P2P IF)...\n")); return; } else { DBGPRINT(RT_DEBUG_TRACE, ("Register CFG80211 I/F (%s)\n", RTMP_OS_NETDEV_GET_DEVNAME(new_dev_p))); } RTMP_OS_NETDEV_SET_PRIV(new_dev_p, pAd); memmove(&pNetDevOps->devAddr[0], &pAd->CurrentAddress[0], MAC_ADDR_LEN); pNetDevOps->needProtcted = true; pWdev = kzalloc(sizeof(*pWdev), GFP_KERNEL); if (unlikely(!pWdev)) { DBGPRINT(RT_DEBUG_ERROR, ("Could not allocate wireless device\n")); return; } new_dev_p->ieee80211_ptr = pWdev; pWdev->wiphy = p80211CB->pCfg80211_Wdev->wiphy; SET_NETDEV_DEV(new_dev_p, wiphy_dev(pWdev->wiphy)); pWdev->netdev = new_dev_p; pWdev->iftype = RT_CMD_80211_IFTYPE_STATION; RtmpOSNetDevAttach(pAd->OpMode, new_dev_p, pNetDevOps); cfg80211_ctrl->dummy_p2p_net_dev = new_dev_p; cfg80211_ctrl->flg_cfg_dummy_p2p_init = true; DBGPRINT(RT_DEBUG_TRACE, (" %s <=====\n", __FUNCTION__)); }
/* ======================================================================== Routine Description: Initialize Multi-BSS function. Arguments: pAd points to our adapter pDevMain points to the main BSS network interface Return Value: None Note: 1. Only create and initialize virtual network interfaces. 2. No main network interface here. 3. If you down ra0 and modify the BssNum of RT2860AP.dat/RT2870AP.dat, it will not work! You must rmmod rt2860ap.ko and lsmod rt2860ap.ko again. ======================================================================== */ VOID MBSS_Init(RTMP_ADAPTER *pAd, RTMP_OS_NETDEV_OP_HOOK *pNetDevOps) { #define MBSS_MAX_DEV_NUM 32 PNET_DEV pDevNew; INT32 IdBss, MaxNumBss; INT status; RTMP_OS_NETDEV_OP_HOOK netDevHook; /* sanity check to avoid redundant virtual interfaces are created */ if (pAd->FlgMbssInit != FALSE) return; MaxNumBss = pAd->ApCfg.BssidNum; if (MaxNumBss > MAX_MBSSID_NUM(pAd)) MaxNumBss = MAX_MBSSID_NUM(pAd); /* first IdBss must not be 0 (BSS0), must be 1 (BSS1) */ for(IdBss=FIRST_MBSSID; IdBss<MAX_MBSSID_NUM(pAd); IdBss++) pAd->ApCfg.MBSSID[IdBss].wdev.if_dev = NULL; /* create virtual network interface */ for(IdBss=FIRST_MBSSID; IdBss<MaxNumBss; IdBss++) { struct wifi_dev *wdev; UINT32 MC_RowID = 0, IoctlIF = 0; char *dev_name; #ifdef MULTIPLE_CARD_SUPPORT MC_RowID = pAd->MC_RowID; #endif /* MULTIPLE_CARD_SUPPORT */ #ifdef HOSTAPD_SUPPORT IoctlIF = pAd->IoctlIF; #endif /* HOSTAPD_SUPPORT */ dev_name = get_dev_name_prefix(pAd, INT_MBSSID); pDevNew = RtmpOSNetDevCreate(MC_RowID, &IoctlIF, INT_MBSSID, IdBss, sizeof(struct mt_dev_priv), dev_name); #ifdef HOSTAPD_SUPPORT pAd->IoctlIF = IoctlIF; #endif /* HOSTAPD_SUPPORT */ if (pDevNew == NULL) { pAd->ApCfg.BssidNum = IdBss; /* re-assign new MBSS number */ break; } else { DBGPRINT(RT_DEBUG_TRACE, ("Register MBSSID IF (%s)\n", RTMP_OS_NETDEV_GET_DEVNAME(pDevNew))); } wdev = &pAd->ApCfg.MBSSID[IdBss].wdev; wdev->wdev_type = WDEV_TYPE_AP; wdev->func_dev = &pAd->ApCfg.MBSSID[IdBss]; wdev->sys_handle = (void *)pAd; wdev->if_dev = pDevNew; if (rtmp_wdev_idx_reg(pAd, wdev) < 0) { DBGPRINT(RT_DEBUG_ERROR, ("Assign wdev idx for %s failed, free net device!\n", RTMP_OS_NETDEV_GET_DEVNAME(pDevNew))); RtmpOSNetDevFree(pDevNew); break; } wdev->tx_pkt_allowed = ApAllowToSendPacket; RTMP_OS_NETDEV_SET_PRIV(pDevNew, pAd); RTMP_OS_NETDEV_SET_WDEV(pDevNew, wdev); /* init operation functions and flags */ NdisCopyMemory(&netDevHook, pNetDevOps, sizeof(netDevHook)); netDevHook.priv_flags = INT_MBSSID; netDevHook.needProtcted = TRUE; netDevHook.wdev = wdev; /* Init MAC address of virtual network interface */ NdisMoveMemory(&netDevHook.devAddr[0], &wdev->bssid[0], MAC_ADDR_LEN); /* register this device to OS */ status = RtmpOSNetDevAttach(pAd->OpMode, pDevNew, &netDevHook); } pAd->FlgMbssInit = TRUE; }
VOID RTMP_CFG80211_VirtualIF_Init( IN VOID *pAdSrc, IN CHAR *pDevName, IN UINT32 DevType) { PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)pAdSrc; RTMP_OS_NETDEV_OP_HOOK netDevHook, *pNetDevOps; PNET_DEV new_dev_p; #ifdef RT_CFG80211_P2P_SUPPORT APCLI_STRUCT *pApCliEntry; #endif /* RT_CFG80211_P2P_SUPPORT */ struct wifi_dev *wdev; CHAR preIfName[12]; UINT devNameLen = strlen(pDevName); UINT preIfIndex = pDevName[devNameLen-1] - 48; CFG80211_CB *p80211CB = pAd->pCfg80211_CB; struct wireless_dev *pWdev; UINT32 MC_RowID = 0, IoctlIF = 0, Inf = INT_P2P; memset(preIfName, 0, sizeof(preIfName)); NdisCopyMemory(preIfName, pDevName, devNameLen-1); pNetDevOps=&netDevHook; DBGPRINT(RT_DEBUG_TRACE, ("%s ---> (%s, %s, %d)\n", __FUNCTION__, pDevName, preIfName, preIfIndex)); /* init operation functions and flags */ NdisZeroMemory(&netDevHook, sizeof(netDevHook)); netDevHook.open = CFG80211_VirtualIF_Open; /* device opem hook point */ netDevHook.stop = CFG80211_VirtualIF_Close; /* device close hook point */ netDevHook.xmit = CFG80211_VirtualIF_PacketSend; /* hard transmit hook point */ netDevHook.ioctl = CFG80211_VirtualIF_Ioctl; /* ioctl hook point */ #if WIRELESS_EXT >= 12 //netDevHook.iw_handler = (void *)&rt28xx_ap_iw_handler_def; #endif /* WIRELESS_EXT >= 12 */ new_dev_p = RtmpOSNetDevCreate(MC_RowID, &IoctlIF, Inf, preIfIndex, sizeof(PRTMP_ADAPTER), preIfName); if (new_dev_p == NULL) { /* allocation fail, exit */ DBGPRINT(RT_DEBUG_ERROR, ("Allocate network device fail (CFG80211)...\n")); return; } else { DBGPRINT(RT_DEBUG_TRACE, ("Register CFG80211 I/F (%s)\n", RTMP_OS_NETDEV_GET_DEVNAME(new_dev_p))); } new_dev_p->destructor = free_netdev; RTMP_OS_NETDEV_SET_PRIV(new_dev_p, pAd); pNetDevOps->needProtcted = TRUE; NdisMoveMemory(&pNetDevOps->devAddr[0], &pAd->CurrentAddress[0], MAC_ADDR_LEN); //CFG_TODO /* Bit1 of MAC address Byte0 is local administration bit and should be set to 1 in extended multiple BSSIDs' Bit3~ of MAC address Byte0 is extended multiple BSSID index. */ if (pAd->chipCap.MBSSIDMode == MBSSID_MODE1) pNetDevOps->devAddr[0] += 2; /* NEW BSSID */ else { #ifdef P2P_ODD_MAC_ADJUST if (pNetDevOps->devAddr[5] & 0x01 == 0x01) pNetDevOps->devAddr[5] -= 1; else #endif /* P2P_ODD_MAC_ADJUST */ pNetDevOps->devAddr[5] += FIRST_MBSSID; } switch (DevType) { case RT_CMD_80211_IFTYPE_MONITOR: DBGPRINT(RT_DEBUG_ERROR, ("CFG80211 I/F Monitor Type\n")); //RTMP_OS_NETDEV_SET_TYPE_MONITOR(new_dev_p); break; #ifdef RT_CFG80211_P2P_SUPPORT case RT_CMD_80211_IFTYPE_P2P_CLIENT: pApCliEntry = &pAd->ApCfg.ApCliTab[MAIN_MBSSID]; wdev = &pApCliEntry->wdev; wdev->wdev_type = WDEV_TYPE_STA; wdev->func_dev = pApCliEntry; wdev->sys_handle = (void *)pAd; wdev->if_dev = new_dev_p; wdev->tx_pkt_allowed = ApCliAllowToSendPacket; RTMP_OS_NETDEV_SET_PRIV(new_dev_p, pAd); RTMP_OS_NETDEV_SET_WDEV(new_dev_p, wdev); if (rtmp_wdev_idx_reg(pAd, wdev) < 0) { DBGPRINT(RT_DEBUG_ERROR, ("%s: Assign wdev idx for %s failed, free net device!\n", __FUNCTION__,RTMP_OS_NETDEV_GET_DEVNAME(new_dev_p))); RtmpOSNetDevFree(new_dev_p); break; } /* init MAC address of virtual network interface */ COPY_MAC_ADDR(wdev->if_addr, pNetDevOps->devAddr); break; case RT_CMD_80211_IFTYPE_P2P_GO: pNetDevOps->priv_flags = INT_P2P; pAd->ApCfg.MBSSID[MAIN_MBSSID].MSSIDDev = NULL; /* The Behivaor in SetBeacon Ops */ //pAd->ApCfg.MBSSID[MAIN_MBSSID].MSSIDDev = new_dev_p; pAd->cfg80211_ctrl.isCfgInApMode = RT_CMD_80211_IFTYPE_AP; COPY_MAC_ADDR(pAd->ApCfg.MBSSID[MAIN_MBSSID].wdev.if_addr, pNetDevOps->devAddr); COPY_MAC_ADDR(pAd->ApCfg.MBSSID[MAIN_MBSSID].wdev.bssid, pNetDevOps->devAddr); break; #endif /* RT_CFG80211_P2P_SUPPORT */ default: DBGPRINT(RT_DEBUG_ERROR, ("Unknown CFG80211 I/F Type (%d)\n", DevType)); } //CFG_TODO : should be move to VIF_CHG if ((DevType == RT_CMD_80211_IFTYPE_P2P_CLIENT) || (DevType == RT_CMD_80211_IFTYPE_P2P_GO)) { COPY_MAC_ADDR(pAd->cfg80211_ctrl.P2PCurrentAddress, pNetDevOps->devAddr); } pWdev = kzalloc(sizeof(*pWdev), GFP_KERNEL); new_dev_p->ieee80211_ptr = pWdev; pWdev->wiphy = p80211CB->pCfg80211_Wdev->wiphy; SET_NETDEV_DEV(new_dev_p, wiphy_dev(pWdev->wiphy)); pWdev->netdev = new_dev_p; pWdev->iftype = DevType; RtmpOSNetDevAttach(pAd->OpMode, new_dev_p, pNetDevOps); AsicSetBssid(pAd, pAd->CurrentAddress); /* Record the pNetDevice to Cfg80211VifDevList */ RTMP_CFG80211_AddVifEntry(pAd, new_dev_p, DevType); DBGPRINT(RT_DEBUG_TRACE, ("%s <---\n", __FUNCTION__)); }
VOID MBSS_Init( IN PRTMP_ADAPTER pAd, IN RTMP_OS_NETDEV_OP_HOOK *pNetDevOps) { #define MBSS_MAX_DEV_NUM 32 PNET_DEV pDevNew; INT32 IdBss, MaxNumBss; int status; RTMP_OS_NETDEV_OP_HOOK netDevHook; /* sanity check to avoid redundant virtual interfaces are created */ if (pAd->FlgMbssInit != FALSE) return; /* init */ MaxNumBss = pAd->ApCfg.BssidNum; if (MaxNumBss > MAX_MBSSID_NUM(pAd)) MaxNumBss = MAX_MBSSID_NUM(pAd); /* first IdBss must not be 0 (BSS0), must be 1 (BSS1) */ for(IdBss=FIRST_MBSSID; IdBss<MAX_MBSSID_NUM(pAd); IdBss++) pAd->ApCfg.MBSSID[IdBss].MSSIDDev = NULL; /* create virtual network interface */ for(IdBss=FIRST_MBSSID; IdBss<MaxNumBss; IdBss++) { UINT32 MC_RowID = 0, IoctlIF = 0; #ifdef MULTIPLE_CARD_SUPPORT MC_RowID = pAd->MC_RowID; #endif /* MULTIPLE_CARD_SUPPORT */ #ifdef HOSTAPD_SUPPORT IoctlIF = pAd->IoctlIF; #endif /* HOSTAPD_SUPPORT */ pDevNew = RtmpOSNetDevCreate(MC_RowID, &IoctlIF, INT_MBSSID, IdBss, sizeof(PRTMP_ADAPTER), INF_MBSSID_DEV_NAME); #ifdef HOSTAPD_SUPPORT pAd->IoctlIF = IoctlIF; #endif /* HOSTAPD_SUPPORT */ if (pDevNew == NULL) { /* allocation fail, exit */ pAd->ApCfg.BssidNum = IdBss; /* re-assign new MBSS number */ DBGPRINT(RT_DEBUG_ERROR, ("Allocate network device fail (MBSS)...\n")); break; } else { DBGPRINT(RT_DEBUG_TRACE, ("Register MBSSID IF (%s)\n", RTMP_OS_NETDEV_GET_DEVNAME(pDevNew))); } RTMP_OS_NETDEV_SET_PRIV(pDevNew, pAd); /* init operation functions and flags */ NdisCopyMemory(&netDevHook, pNetDevOps, sizeof(netDevHook)); netDevHook.priv_flags = INT_MBSSID; /* We are virtual interface */ netDevHook.needProtcted = TRUE; /* Init MAC address of virtual network interface */ NdisMoveMemory(&netDevHook.devAddr[0], &pAd->ApCfg.MBSSID[IdBss].Bssid[0], MAC_ADDR_LEN); /* backup our virtual network interface */ pAd->ApCfg.MBSSID[IdBss].MSSIDDev = pDevNew; /* register this device to OS */ status = RtmpOSNetDevAttach(pAd->OpMode, pDevNew, &netDevHook); } pAd->FlgMbssInit = TRUE; }
int rt2880_module_init(VOID) { struct net_device *net_dev = NULL; ULONG csr_addr; INT rv; PVOID *handle = NULL; RTMP_ADAPTER *pAd = NULL; unsigned int dev_irq; RTMP_OS_NETDEV_OP_HOOK netDevHook; DBGPRINT(RT_DEBUG_TRACE, ("===> rt2880_probe\n")); //RtmpRaBusInit============================================ // map physical address to virtual address for accessing register csr_addr = (unsigned long)RTMP_MAC_CSR_ADDR; dev_irq = RTMP_MAC_IRQ_NUM; //RtmpDevInit============================================== // Allocate RTMP_ADAPTER adapter structure handle = kmalloc(sizeof(struct os_cookie) , GFP_KERNEL); if (!handle) { DBGPRINT(RT_DEBUG_ERROR, ("Allocate memory for os_cookie failed!\n")); goto err_out; } NdisZeroMemory(handle, sizeof(struct os_cookie)); rv = RTMPAllocAdapterBlock(handle, &pAd); if (rv != NDIS_STATUS_SUCCESS) { DBGPRINT(RT_DEBUG_ERROR, (" RTMPAllocAdapterBlock != NDIS_STATUS_SUCCESS\n")); kfree(handle); goto err_out; } // Here are the RTMP_ADAPTER structure with rbus-bus specific parameters. pAd->CSRBaseAddress = (PUCHAR)csr_addr; RtmpRaDevCtrlInit(pAd, RTMP_DEV_INF_RBUS); //NetDevInit============================================== net_dev = RtmpPhyNetDevInit(pAd, &netDevHook); if (net_dev == NULL) goto err_out_free_radev; // Here are the net_device structure with pci-bus specific parameters. net_dev->irq = dev_irq; // Interrupt IRQ number net_dev->base_addr = csr_addr; // Save CSR virtual address and irq to device structure ((POS_COOKIE)handle)->pci_dev = (struct pci_dev *)net_dev; #ifdef CONFIG_STA_SUPPORT pAd->StaCfg.OriDevType = net_dev->type; #endif // CONFIG_STA_SUPPORT // //All done, it's time to register the net device to kernel. // Register this device rv = RtmpOSNetDevAttach(net_dev, &netDevHook); if (rv) { DBGPRINT(RT_DEBUG_ERROR, ("failed to call RtmpOSNetDevAttach(), rv=%d!\n", rv)); goto err_out_free_netdev; } // due to we didn't have any hook point when do module remove, we use this static as our hook point. rt2880_dev = net_dev; wl_proc_init(); DBGPRINT(RT_DEBUG_TRACE, ("%s: at CSR addr 0x%1lx, IRQ %d. \n", net_dev->name, (ULONG)csr_addr, net_dev->irq)); DBGPRINT(RT_DEBUG_TRACE, ("<=== rt2880_probe\n")); return 0; err_out_free_netdev: RtmpOSNetDevFree(net_dev); err_out_free_radev: /* free RTMP_ADAPTER strcuture and os_cookie*/ RTMPFreeAdapter(pAd); err_out: return -ENODEV; }
static int __devinit rt2860_probe(IN struct pci_dev *pci_dev, IN const struct pci_device_id *pci_id) { struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)NULL; struct net_device *net_dev; void *handle; char *print_name; unsigned long csr_addr; int rv = 0; struct rt_rtmp_os_netdev_op_hook netDevHook; DBGPRINT(RT_DEBUG_TRACE, ("===> rt2860_probe\n")); /*PCIDevInit============================================== */ /* wake up and enable device */ if ((rv = pci_enable_device(pci_dev)) != 0) { DBGPRINT(RT_DEBUG_ERROR, ("Enable PCI device failed, errno=%d!\n", rv)); return rv; } print_name = (char *)pci_name(pci_dev); if ((rv = pci_request_regions(pci_dev, print_name)) != 0) { DBGPRINT(RT_DEBUG_ERROR, ("Request PCI resource failed, errno=%d!\n", rv)); goto err_out; } /* map physical address to virtual address for accessing register */ csr_addr = (unsigned long)ioremap(pci_resource_start(pci_dev, 0), pci_resource_len(pci_dev, 0)); if (!csr_addr) { DBGPRINT(RT_DEBUG_ERROR, ("ioremap failed for device %s, region 0x%lX @ 0x%lX\n", print_name, (unsigned long)pci_resource_len(pci_dev, 0), (unsigned long)pci_resource_start(pci_dev, 0))); goto err_out_free_res; } else { DBGPRINT(RT_DEBUG_TRACE, ("%s: at 0x%lx, VA 0x%lx, IRQ %d. \n", print_name, (unsigned long)pci_resource_start(pci_dev, 0), (unsigned long)csr_addr, pci_dev->irq)); } /* Set DMA master */ pci_set_master(pci_dev); /*RtmpDevInit============================================== */ /* Allocate struct rt_rtmp_adapter adapter structure */ handle = kmalloc(sizeof(struct os_cookie), GFP_KERNEL); if (handle == NULL) { DBGPRINT(RT_DEBUG_ERROR, ("%s(): Allocate memory for os handle failed!\n", __func__)); goto err_out_iounmap; } ((struct os_cookie *)handle)->pci_dev = pci_dev; rv = RTMPAllocAdapterBlock(handle, &pAd); /*shiang: we may need the pci_dev for allocate structure of "struct rt_rtmp_adapter" */ if (rv != NDIS_STATUS_SUCCESS) goto err_out_iounmap; /* Here are the struct rt_rtmp_adapter structure with pci-bus specific parameters. */ pAd->CSRBaseAddress = (u8 *)csr_addr; DBGPRINT(RT_DEBUG_ERROR, ("pAd->CSRBaseAddress =0x%lx, csr_addr=0x%lx!\n", (unsigned long)pAd->CSRBaseAddress, csr_addr)); RtmpRaDevCtrlInit(pAd, RTMP_DEV_INF_PCI); /*NetDevInit============================================== */ net_dev = RtmpPhyNetDevInit(pAd, &netDevHook); if (net_dev == NULL) goto err_out_free_radev; /* Here are the net_device structure with pci-bus specific parameters. */ net_dev->irq = pci_dev->irq; /* Interrupt IRQ number */ net_dev->base_addr = csr_addr; /* Save CSR virtual address and irq to device structure */ pci_set_drvdata(pci_dev, net_dev); /* Set driver data */ /* for supporting Network Manager */ /* Set the sysfs physical device reference for the network logical device * if set prior to registration will cause a symlink during initialization. */ SET_NETDEV_DEV(net_dev, &(pci_dev->dev)); /*All done, it's time to register the net device to linux kernel. */ /* Register this device */ rv = RtmpOSNetDevAttach(net_dev, &netDevHook); if (rv) goto err_out_free_netdev; pAd->StaCfg.OriDevType = net_dev->type; RTMPInitPCIeDevice(pci_dev, pAd); DBGPRINT(RT_DEBUG_TRACE, ("<=== rt2860_probe\n")); return 0; /* probe ok */ /* --------------------------- ERROR HANDLE --------------------------- */ err_out_free_netdev: RtmpOSNetDevFree(net_dev); err_out_free_radev: /* free struct rt_rtmp_adapter strcuture and os_cookie */ RTMPFreeAdapter(pAd); err_out_iounmap: iounmap((void *)(csr_addr)); release_mem_region(pci_resource_start(pci_dev, 0), pci_resource_len(pci_dev, 0)); err_out_free_res: pci_release_regions(pci_dev); err_out: pci_disable_device(pci_dev); DBGPRINT(RT_DEBUG_ERROR, ("<=== rt2860_probe failed with rv = %d!\n", rv)); return -ENODEV; /* probe fail */ }
/* PCI device probe & initialization function */ static int DEVINIT rt_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pci_id) { void *pAd = NULL, *handle; struct net_device *net_dev; const char *print_name; unsigned long csr_addr; int rv = 0; RTMP_OS_NETDEV_OP_HOOK netDevHook; unsigned long OpMode; DBGPRINT(RT_DEBUG_TRACE, ("===> %s()\n", __FUNCTION__)); /*PCIDevInit============================================== */ /* wake up and enable device */ if ((rv = pci_enable_device(pdev))!= 0) { DBGPRINT(RT_DEBUG_ERROR, ("Enable PCI device failed, errno=%d!\n", rv)); return rv; } #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) print_name = pci_name(pdev); #else print_name = pdev->slot_name; #endif /* LINUX_VERSION_CODE */ if ((rv = pci_request_regions(pdev, print_name)) != 0) { DBGPRINT(RT_DEBUG_ERROR, ("Request PCI resource failed, errno=%d!\n", rv)); goto err_out; } /* map physical address to virtual address for accessing register */ csr_addr = (unsigned long) ioremap(pci_resource_start(pdev, 0), pci_resource_len(pdev, 0)); if (!csr_addr) { DBGPRINT(RT_DEBUG_ERROR, ("ioremap failed for device %s, region 0x%lX @ 0x%lX\n", print_name, (ULONG)pci_resource_len(pdev, 0), (ULONG)pci_resource_start(pdev, 0))); goto err_out_free_res; } else { DBGPRINT(RT_DEBUG_TRACE, ("%s: at 0x%lx, VA 0x%lx, IRQ %d. \n", print_name, (ULONG)pci_resource_start(pdev, 0), (ULONG)csr_addr, pdev->irq)); } /* Set DMA master */ pci_set_master(pdev); /* Allocate RTMP_ADAPTER adapter structure */ os_alloc_mem(NULL, (UCHAR **)&handle, sizeof(struct os_cookie)); if (handle == NULL) { DBGPRINT(RT_DEBUG_ERROR, ("%s(): Allocate memory for os handle failed!\n", __FUNCTION__)); goto err_out_iounmap; } memset(handle, 0, sizeof(struct os_cookie)); ((POS_COOKIE)handle)->pci_dev = pdev; #ifdef OS_ABL_FUNC_SUPPORT { RTMP_PCI_CONFIG PciConfig; PciConfig.ConfigVendorID = PCI_VENDOR_ID; /* get DRIVER operations */ RTMP_DRV_OPS_FUNCTION(pRtmpDrvOps, NULL, &PciConfig, NULL); } #endif /* OS_ABL_FUNC_SUPPORT */ rv = RTMPAllocAdapterBlock(handle, &pAd); /* we may need the pdev for allocate structure of "RTMP_ADAPTER" */ if (rv != NDIS_STATUS_SUCCESS) goto err_out_iounmap; #ifdef MULTI_INF_SUPPORT if (pAdGlobalList[0] == NULL) pAdGlobalList[0] = pAd; else if (pAdGlobalList[1] == NULL) pAdGlobalList[1] = pAd; else DBGPRINT(RT_DEBUG_ERROR, ("%s(): pAdGlobalList assign Error !\n", __FUNCTION__)); #endif /* MULTI_INF_SUPPORT */ RTMP_DRIVER_PCI_CSR_SET(pAd, csr_addr); RTMP_DRIVER_PCIE_INIT(pAd, pdev); /*NetDevInit============================================== */ net_dev = RtmpPhyNetDevInit(pAd, &netDevHook); if (net_dev == NULL) goto err_out_free_radev; /* Here are the net_device structure with pci-bus specific parameters. */ net_dev->irq = pdev->irq; /* Interrupt IRQ number */ net_dev->base_addr = csr_addr; /* Save CSR virtual address and irq to device structure */ pci_set_drvdata(pdev, net_dev); /* Set driver data */ /*All done, it's time to register the net device to linux kernel. */ /* Register this device */ #ifdef RT_CFG80211_SUPPORT { /* pAd->pCfgDev = &(pdev->dev); */ /* pAd->CFG80211_Register = CFG80211_Register; */ /* RTMP_DRIVER_CFG80211_INIT(pAd, pdev); */ /* In 2.6.32, cfg80211 register must be before register_netdevice(); We can not put the register in rt28xx_open(); Or you will suffer NULL pointer in list_add of cfg80211_netdev_notifier_call(). */ CFG80211_Register(pAd, &(pdev->dev), net_dev); } #endif /* RT_CFG80211_SUPPORT */ RTMP_DRIVER_OP_MODE_GET(pAd, &OpMode); rv = RtmpOSNetDevAttach(OpMode, net_dev, &netDevHook); if (rv) goto err_out_free_netdev; #ifdef PRE_ASSIGN_MAC_ADDR { UCHAR mac_addr[MAC_ADDR_LEN]; RTMP_DRIVER_MAC_ADDR_GET(pAd, &mac_addr[0]); DBGPRINT(RT_DEBUG_TRACE, ("@%s MAC address: %02x:%02x:%02x:%02x:%02x:%02x\n", __FUNCTION__, mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5])); /* Set up the Mac address */ RtmpOSNetDevAddrSet(OpMode, net_dev, &mac_addr[0], NULL); } #endif /* PRE_ASSIGN_MAC_ADDR */ DBGPRINT(RT_DEBUG_TRACE, ("<=== %s()\n", __FUNCTION__)); return 0; /* probe ok */ /* --------------------------- ERROR HANDLE --------------------------- */ err_out_free_netdev: RtmpOSNetDevFree(net_dev); err_out_free_radev: /* free RTMP_ADAPTER strcuture and os_cookie*/ RTMPFreeAdapter(pAd); err_out_iounmap: iounmap((void *)(csr_addr)); release_mem_region(pci_resource_start(pdev, 0), pci_resource_len(pdev, 0)); err_out_free_res: pci_release_regions(pdev); err_out: pci_disable_device(pdev); DBGPRINT(RT_DEBUG_ERROR, ("<=== %s() failed with rv = %d!\n", __FUNCTION__, rv)); return -ENODEV; /* probe fail */ }
static INT __devinit rt2860_probe( IN struct pci_dev *pci_dev, IN const struct pci_device_id *pci_id) { PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)NULL; struct net_device *net_dev; PVOID handle; PSTRING print_name; ULONG csr_addr; INT rv = 0; RTMP_OS_NETDEV_OP_HOOK netDevHook; #ifdef RT30xx static UCHAR MemReset=0; #endif // RT3090 // DBGPRINT(RT_DEBUG_TRACE, ("===> rt2860_probe\n")); //PCIDevInit============================================== // wake up and enable device if ((rv = pci_enable_device(pci_dev))!= 0) { DBGPRINT(RT_DEBUG_ERROR, ("Enable PCI device failed, errno=%d!\n", rv)); return rv; } #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) print_name = pci_dev ? (PSTRING)pci_name(pci_dev) : "rt2860"; #else print_name = pci_dev ? pci_dev->slot_name : "rt2860"; #endif // LINUX_VERSION_CODE // if ((rv = pci_request_regions(pci_dev, print_name)) != 0) { DBGPRINT(RT_DEBUG_ERROR, ("Request PCI resource failed, errno=%d!\n", rv)); goto err_out; } // map physical address to virtual address for accessing register csr_addr = (unsigned long) ioremap(pci_resource_start(pci_dev, 0), pci_resource_len(pci_dev, 0)); if (!csr_addr) { DBGPRINT(RT_DEBUG_ERROR, ("ioremap failed for device %s, region 0x%lX @ 0x%lX\n", print_name, (ULONG)pci_resource_len(pci_dev, 0), (ULONG)pci_resource_start(pci_dev, 0))); goto err_out_free_res; } else { DBGPRINT(RT_DEBUG_TRACE, ("%s: at 0x%lx, VA 0x%lx, IRQ %d. \n", print_name, (ULONG)pci_resource_start(pci_dev, 0), (ULONG)csr_addr, pci_dev->irq)); } // Set DMA master pci_set_master(pci_dev); //RtmpDevInit============================================== // Allocate RTMP_ADAPTER adapter structure handle = kmalloc(sizeof(struct os_cookie), GFP_KERNEL); if (handle == NULL) { DBGPRINT(RT_DEBUG_ERROR, ("%s(): Allocate memory for os handle failed!\n", __FUNCTION__)); goto err_out_iounmap; } memset(handle, 0, sizeof(struct os_cookie)); ((POS_COOKIE)handle)->pci_dev = pci_dev; rv = RTMPAllocAdapterBlock(handle, &pAd); //shiang: we may need the pci_dev for allocate structure of "RTMP_ADAPTER" if (rv != NDIS_STATUS_SUCCESS) goto err_out_iounmap; // Here are the RTMP_ADAPTER structure with pci-bus specific parameters. pAd->CSRBaseAddress = (PUCHAR)csr_addr; DBGPRINT(RT_DEBUG_ERROR, ("pAd->CSRBaseAddress =0x%lx, csr_addr=0x%lx!\n", (ULONG)pAd->CSRBaseAddress, csr_addr)); #ifdef RT30xx if (MemReset==0) { UINT32 MacCsr0 = 0; UCHAR Index = 0; BOOLEAN NeedResetChips=FALSE; MemReset=1; do { RTMP_IO_READ32(pAd, MAC_CSR0, &MacCsr0); if ((MacCsr0 != 0x00) && (MacCsr0 != 0xFFFFFFFF)) break; RTMPusecDelay(10); } while (Index++ < 100); if (((MacCsr0&0xFFFF0000)==0x3090) ||((MacCsr0&0xFFFF0000)==0x3390)) { if ((MacCsr0&0x0000FFFF) < 0x3213) NeedResetChips=TRUE; } if (((MacCsr0&0xFFFF0000)==0x3071) ) { if ((MacCsr0&0x0000FFFF) < 0x21C) NeedResetChips=TRUE; } if (NeedResetChips==TRUE) { struct proc_dir_entry *tsarm_proc; RTMP_IO_READ32(pAd, 0x5C0,&MacCsr0); MacCsr0|=0x400000; RTMP_IO_WRITE32(pAd, 0x5C0,MacCsr0); OS_WAIT(1000); /* Send reset PCI device event */ //RTMPSendWirelessEvent(pAd, IW_RESETPCI_EVENT_FLAG, NULL, BSS0, 0); RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST); tsarm_proc = create_proc_entry("TwoM", 0, NULL); if (tsarm_proc) { tsarm_proc->read_proc = twoPortM_read_proc; tsarm_proc->write_proc = twoPortM_write_proc; } goto err_out_free_radev; } } #endif // RT3090 // RTMPInitPCIeDevice(pci_dev, pAd); //NetDevInit============================================== net_dev = RtmpPhyNetDevInit(pAd, &netDevHook); if (net_dev == NULL) goto err_out_free_radev; // Here are the net_device structure with pci-bus specific parameters. net_dev->irq = pci_dev->irq; // Interrupt IRQ number net_dev->base_addr = csr_addr; // Save CSR virtual address and irq to device structure pci_set_drvdata(pci_dev, net_dev); // Set driver data //All done, it's time to register the net device to linux kernel. // Register this device #ifdef RT_CFG80211_SUPPORT pAd->pCfgDev = &(pci_dev->dev); pAd->CFG80211_Register = CFG80211_Register; #endif // RT_CFG80211_SUPPORT // rv = RtmpOSNetDevAttach(net_dev, &netDevHook); if (rv) goto err_out_free_netdev; #ifdef KTHREAD_SUPPORT init_waitqueue_head(&pAd->cmdQTask.kthread_q); #ifdef WSC_INCLUDED init_waitqueue_head(&pAd->wscTask.kthread_q); #endif #endif // KTHREAD_SUPPORT // DBGPRINT(RT_DEBUG_TRACE, ("<=== rt2860_probe\n")); return 0; // probe ok /* --------------------------- ERROR HANDLE --------------------------- */ err_out_free_netdev: RtmpOSNetDevFree(net_dev); err_out_free_radev: /* free RTMP_ADAPTER strcuture and os_cookie*/ RTMPFreeAdapter(pAd); err_out_iounmap: iounmap((void *)(csr_addr)); release_mem_region(pci_resource_start(pci_dev, 0), pci_resource_len(pci_dev, 0)); err_out_free_res: pci_release_regions(pci_dev); err_out: pci_disable_device(pci_dev); DBGPRINT(RT_DEBUG_ERROR, ("<=== rt2860_probe failed with rv = %d!\n", rv)); return -ENODEV; /* probe fail */ }
/* ======================================================================== Routine Description: Initialize Multi-BSS function. Arguments: pAd points to our adapter pDevMain points to the main BSS network interface Return Value: None Note: 1. Only create and initialize virtual network interfaces. 2. No main network interface here. 3. If you down ra0 and modify the BssNum of RT2860AP.dat/RT2870AP.dat, it will not work! You must rmmod rt2860ap.ko and lsmod rt2860ap.ko again. ======================================================================== */ VOID RT28xx_MBSS_Init( IN PRTMP_ADAPTER pAd, IN PNET_DEV pDevMain) { #define MBSS_MAX_DEV_NUM 32 PNET_DEV pDevNew; INT32 IdBss, MaxNumBss; INT status; RTMP_OS_NETDEV_OP_HOOK netDevHook; /* sanity check to avoid redundant virtual interfaces are created */ if (pAd->FlgMbssInit != FALSE) return; /* End of if */ /* init */ MaxNumBss = pAd->ApCfg.BssidNum; if (MaxNumBss > MAX_MBSSID_NUM) MaxNumBss = MAX_MBSSID_NUM; /* End of if */ /* first IdBss must not be 0 (BSS0), must be 1 (BSS1) */ for(IdBss=FIRST_MBSSID; IdBss<MAX_MBSSID_NUM; IdBss++) pAd->ApCfg.MBSSID[IdBss].MSSIDDev = NULL; /* End of for */ /* create virtual network interface */ for(IdBss=FIRST_MBSSID; IdBss<MaxNumBss; IdBss++) { pDevNew = RtmpOSNetDevCreate(pAd, INT_MBSSID, IdBss, sizeof(PRTMP_ADAPTER), INF_MBSSID_DEV_NAME); if (pDevNew == NULL) { /* allocation fail, exit */ pAd->ApCfg.BssidNum = IdBss; /* re-assign new MBSS number */ DBGPRINT(RT_DEBUG_ERROR, ("Allocate network device fail (MBSS)...\n")); break; } else { DBGPRINT(RT_DEBUG_TRACE, ("Register MBSSID IF (%s)\n", RTMP_OS_NETDEV_GET_DEVNAME(pDevNew))); } RTMP_OS_NETDEV_SET_PRIV(pDevNew, pAd); /* init operation functions and flags */ NdisZeroMemory(&netDevHook, sizeof(netDevHook)); netDevHook.open = MBSS_VirtualIF_Open; // device opem hook point netDevHook.stop = MBSS_VirtualIF_Close; // device close hook point netDevHook.xmit = MBSS_VirtualIF_PacketSend; // hard transmit hook point netDevHook.ioctl = MBSS_VirtualIF_Ioctl; // ioctl hook point netDevHook.priv_flags = INT_MBSSID; // We are virtual interface netDevHook.needProtcted = TRUE; /* Init MAC address of virtual network interface */ NdisMoveMemory(&netDevHook.devAddr[0], &pAd->ApCfg.MBSSID[IdBss].Bssid[0], MAC_ADDR_LEN); /* backup our virtual network interface */ pAd->ApCfg.MBSSID[IdBss].MSSIDDev = pDevNew; /* register this device to OS */ status = RtmpOSNetDevAttach(pDevNew, &netDevHook); } pAd->FlgMbssInit = TRUE; }
static INT __devinit rt2860_probe( IN struct pci_dev *pci_dev, IN const struct pci_device_id *pci_id) { PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)NULL; struct net_device *net_dev; PVOID handle; PSTRING print_name; ULONG csr_addr; INT rv = 0; RTMP_OS_NETDEV_OP_HOOK netDevHook; DBGPRINT(RT_DEBUG_TRACE, ("===> rt2860_probe\n")); if ((rv = pci_enable_device(pci_dev))!= 0) { DBGPRINT(RT_DEBUG_ERROR, ("Enable PCI device failed, errno=%d!\n", rv)); return rv; } #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) print_name = pci_dev ? pci_name(pci_dev) : "rt3090"; #else print_name = pci_dev ? pci_dev->slot_name : "rt3090"; #endif if ((rv = pci_request_regions(pci_dev, print_name)) != 0) { DBGPRINT(RT_DEBUG_ERROR, ("Request PCI resource failed, errno=%d!\n", rv)); goto err_out; } csr_addr = (unsigned long) ioremap(pci_resource_start(pci_dev, 0), pci_resource_len(pci_dev, 0)); if (!csr_addr) { DBGPRINT(RT_DEBUG_ERROR, ("ioremap failed for device %s, region 0x%lX @ 0x%lX\n", print_name, (ULONG)pci_resource_len(pci_dev, 0), (ULONG)pci_resource_start(pci_dev, 0))); goto err_out_free_res; } else { DBGPRINT(RT_DEBUG_TRACE, ("%s: at 0x%lx, VA 0x%lx, IRQ %d. \n", print_name, (ULONG)pci_resource_start(pci_dev, 0), (ULONG)csr_addr, pci_dev->irq)); } pci_set_master(pci_dev); handle = kmalloc(sizeof(struct os_cookie), GFP_KERNEL); if (handle == NULL) { DBGPRINT(RT_DEBUG_ERROR, ("%s(): Allocate memory for os handle failed!\n", __FUNCTION__)); goto err_out_iounmap; } ((POS_COOKIE)handle)->pci_dev = pci_dev; rv = RTMPAllocAdapterBlock(handle, &pAd); if (rv != NDIS_STATUS_SUCCESS) goto err_out_iounmap; pAd->CSRBaseAddress = (PUCHAR)csr_addr; DBGPRINT(RT_DEBUG_ERROR, ("pAd->CSRBaseAddress =0x%lx, csr_addr=0x%lx!\n", (ULONG)pAd->CSRBaseAddress, csr_addr)); RtmpRaDevCtrlInit(pAd, RTMP_DEV_INF_PCI); net_dev = RtmpPhyNetDevInit(pAd, &netDevHook); if (net_dev == NULL) goto err_out_free_radev; net_dev->irq = pci_dev->irq; net_dev->base_addr = csr_addr; pci_set_drvdata(pci_dev, net_dev); #ifdef NATIVE_WPA_SUPPLICANT_SUPPORT #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)) SET_NETDEV_DEV(net_dev, &(pci_dev->dev)); #endif #endif rv = RtmpOSNetDevAttach(net_dev, &netDevHook); if (rv) goto err_out_free_netdev; #ifdef CONFIG_STA_SUPPORT pAd->StaCfg.OriDevType = net_dev->type; #endif RTMPInitPCIeDevice(pci_dev, pAd); DBGPRINT(RT_DEBUG_TRACE, ("<=== rt2860_probe\n")); return 0; err_out_free_netdev: RtmpOSNetDevFree(net_dev); err_out_free_radev: RTMPFreeAdapter(pAd); err_out_iounmap: iounmap((void *)(csr_addr)); release_mem_region(pci_resource_start(pci_dev, 0), pci_resource_len(pci_dev, 0)); err_out_free_res: pci_release_regions(pci_dev); err_out: pci_disable_device(pci_dev); DBGPRINT(RT_DEBUG_ERROR, ("<=== rt2860_probe failed with rv = %d!\n", rv)); return -ENODEV; }