/*************************************************************************** * * PCIe device initialization related procedures. * ***************************************************************************/ static VOID RTMPInitPCIeDevice( IN struct pci_dev *pci_dev, IN PRTMP_ADAPTER pAd) { USHORT device_id; POS_COOKIE pObj; pObj = (POS_COOKIE) pAd->OS_Cookie; pci_read_config_word(pci_dev, PCI_DEVICE_ID, &device_id); device_id = le2cpu16(device_id); pObj->DeviceID = device_id; OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_ADVANCE_POWER_SAVE_PCIE_DEVICE); if ( #ifdef RT2860 (device_id == NIC2860_PCIe_DEVICE_ID) || (device_id == NIC2790_PCIe_DEVICE_ID) || (device_id == VEN_AWT_PCIe_DEVICE_ID) || #endif // RT2860 // 0) { UINT32 MacCsr0 = 0, Index= 0; do { RTMP_IO_READ32(pAd, MAC_CSR0, &MacCsr0); if ((MacCsr0 != 0x00) && (MacCsr0 != 0xFFFFFFFF)) break; RTMPusecDelay(10); } while (Index++ < 100); // Support advanced power save after 2892/2790. // MAC version at offset 0x1000 is 0x2872XXXX/0x2870XXXX(PCIe, USB, SDIO). if ((MacCsr0&0xffff0000) != 0x28600000) { #ifdef PCIE_PS_SUPPORT OPSTATUS_SET_FLAG(pAd, fOP_STATUS_ADVANCE_POWER_SAVE_PCIE_DEVICE); #endif // PCIE_PS_SUPPORT // RtmpRaDevCtrlInit(pAd, RTMP_DEV_INF_PCIE); return; } } RtmpRaDevCtrlInit(pAd, RTMP_DEV_INF_PCI); }
/*************************************************************************** * * PCIe device initialization related procedures. * ***************************************************************************/ static VOID RTMPInitPCIeDevice( IN struct pci_dev *pci_dev, IN PRTMP_ADAPTER pAd) { USHORT device_id; POS_COOKIE pObj; #ifdef RT3090 USHORT subDev_id, subVendor_id; #endif // RT3090 // pObj = (POS_COOKIE) pAd->OS_Cookie; pci_read_config_word(pci_dev, PCI_DEVICE_ID, &device_id); device_id = le2cpu16(device_id); pObj->DeviceID = device_id; #ifdef RT3090 pci_read_config_word(pci_dev, PCI_SUBSYSTEM_VENDOR_ID, &subVendor_id); subVendor_id = le2cpu16(subVendor_id); pci_read_config_word(pci_dev, PCI_SUBSYSTEM_ID, &subDev_id); subDev_id = le2cpu16(subDev_id); #endif // RT3090 // OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_ADVANCE_POWER_SAVE_PCIE_DEVICE); if ( #ifdef RT3090 (device_id == NIC3090_PCIe_DEVICE_ID) || (device_id == NIC3091_PCIe_DEVICE_ID) || (device_id == NIC3092_PCIe_DEVICE_ID) || #endif // RT3090 // #ifdef RT3390 (device_id == NIC3390_PCIe_DEVICE_ID)|| #endif // RT3390 // 0) { UINT32 MacCsr0 = 0, Index= 0; do { RTMP_IO_READ32(pAd, MAC_CSR0, &MacCsr0); if ((MacCsr0 != 0x00) && (MacCsr0 != 0xFFFFFFFF)) break; RTMPusecDelay(10); } while (Index++ < 100); // Support advanced power save after 2892/2790. // MAC version at offset 0x1000 is 0x2872XXXX/0x2870XXXX(PCIe, USB, SDIO). if ((MacCsr0&0xffff0000) != 0x28600000) { #ifdef PCIE_PS_SUPPORT OPSTATUS_SET_FLAG(pAd, fOP_STATUS_ADVANCE_POWER_SAVE_PCIE_DEVICE); #endif // PCIE_PS_SUPPORT // #ifdef RT3090 if ((subVendor_id == 0x1462) && (subDev_id == 0x891A)) RTMP_SET_MORE_FLAG(pAd, fRTMP_ADAPTER_DISABLE_DOT_11N); else RTMP_CLEAR_MORE_FLAG(pAd, fRTMP_ADAPTER_DISABLE_DOT_11N); #endif // RT3090 // RtmpRaDevCtrlInit(pAd, RTMP_DEV_INF_PCIE); return; } } RtmpRaDevCtrlInit(pAd, RTMP_DEV_INF_PCI); }
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; }
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 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; }
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 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")); //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) : "rt3090"; #else print_name = pci_dev ? pci_dev->slot_name : "rt3090"; #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; } ((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)); 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 #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 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 // 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 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 __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; }