📄 rtmp_main.c
字号:
const unsigned int word, u8 data){ RTUSBWriteBBPRegister(rt2x00dev->pAd, word, data);}static void rt2500usb_read_rf(const struct rt2x00_dev *rt2x00dev, const unsigned int word, u32 *data){ *data = 0;}static void rt2500usb_write_rf(const struct rt2x00_dev *rt2x00dev, const unsigned int word, u32 data){}static const struct rt2x00debug rt73usb_rt2x00debug = { .owner = THIS_MODULE, .csr = { .read = rt73usb_read_csr, .write = rt73usb_write_csr, .word_size = sizeof(u32), .word_count = CSR_REG_SIZE / sizeof(u32), }, .eeprom = { .read = rt73usb_read_eeprom, .write = rt73usb_write_eeprom, .word_size = sizeof(u16), .word_count = EEPROM_SIZE / sizeof(u16), }, .bbp = { .read = rt73usb_read_bbp, .write = rt73usb_write_bbp, .word_size = sizeof(u8), .word_count = BBP_SIZE / sizeof(u8), }, .rf = { .read = rt73usb_read_rf, .write = rt73usb_write_rf, .word_size = sizeof(u32), .word_count = RF_SIZE / sizeof(u32), },};static struct rt2x00_dev _rt2x00dev;static struct rt2x00_ops _ops;static void rt73usb_open_debugfs(RTMP_ADAPTER *pAd){ _rt2x00dev.pAd = pAd; _rt2x00dev.ops = &_ops; _rt2x00dev.ops->debugfs = &rt73usb_rt2x00debug; rt2x00debug_register(&_rt2x00dev);}static void rt73usb_close_debugfs(RTMP_ADAPTER *pAd){ rt2x00debug_deregister(&_rt2x00dev);}#else /* RT2X00DEBUGFS */static inline void rt73usb_open_debugfs(RTMP_ADAPTER *pAd){}static inline void rt73usb_close_debugfs(RTMP_ADAPTER *pAd){}#endif /* RT2X00DEBUGFS */#ifdef CONFIG_PMstatic inline int common_suspend(PRTMP_ADAPTER pAd){ struct net_device *netdev; if (!pAd) { DBGPRINT(RT_DEBUG_ERROR, "- %s: dev not specified\n", __FUNCTION__); return -EINVAL; } /* lock the device pointers & shut up compiler under 2.6.26 */ if (down_interruptible(&pAd->usbdev_semaphore)); netdev = pAd->net_dev; if (netif_running(netdev)) { netif_stop_queue(netdev); // need to send it first before USB go susped. // without it system unable to reume back. RTUSBStopRx(pAd); disassocSTA(pAd); RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS); MlmeRadioOff(pAd); RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS); } /* unlock the device pointers */ up(&(pAd->usbdev_semaphore)); DBGPRINT(RT_DEBUG_TRACE,"<-- common_suspend()\n"); return 0;} /* End common_suspend () */static inline int common_resume(PRTMP_ADAPTER pAd){ struct net_device *netdev; if (!pAd) { DBGPRINT(RT_DEBUG_ERROR, "- %s: dev not specified\n", __FUNCTION__); return -EINVAL; } // Remember USB bus power was shut off. NICResetFromError(pAd); if (pAd->PortCfg.AuthMode == Ndis802_11AuthModeWPANone) { AsicAddSharedKeyEntry(pAd, 0, pAd->PortCfg.DefaultKeyId, pAd->SharedKey[pAd->PortCfg.DefaultKeyId].CipherAlg, pAd->SharedKey[pAd->PortCfg.DefaultKeyId].Key, NULL, NULL); } else { AsicAddPairwiseKeyEntry(pAd, pAd->PortCfg.Bssid, pAd->PortCfg.DefaultKeyId, pAd->SharedKey[pAd->PortCfg.DefaultKeyId].CipherAlg, pAd->SharedKey[pAd->PortCfg.DefaultKeyId].Key, NULL, NULL); } netdev = pAd->net_dev; if (netif_running(netdev)) { MlmeRadioOn(pAd); netif_carrier_on(netdev); netif_wake_queue(netdev); } DBGPRINT(RT_DEBUG_TRACE,"<-- common_resume()\n"); return 0;} /* End common_resume () */#endifstatic inline int common_probe(PRTMP_ADAPTER pAd){ //struct net_device *netdev = pAd->net_dev; int Status = 0; UCHAR TmpPhy; if (!reserve_module(THIS_MODULE)) { KPRINT(KERN_CRIT, "cannot reserve module\n"); return -1; } Status = LoadFirmware(pAd, firmName); if (Status) { DBGPRINT(RT_DEBUG_ERROR, "- %s: Failed to load Firmware.\n", __FUNCTION__); KPRINT(KERN_CRIT, "Failed to load Firmware.\n"); goto out; } // Initialize pAd->PortCfg to manufacture default PortCfgInit(pAd); // Init RTMP_ADAPTER CmdQElements RTMPInitAdapterBlock(pAd); // // Init send data structures and related parameters // Status = NICInitTransmit(pAd); // First dynamic memory alloc if (Status != NDIS_STATUS_SUCCESS) { DBGPRINT(RT_DEBUG_TRACE, "<-- %s: Status=%d\n", __FUNCTION__, Status); goto out; } // // Init receive data structures and related parameters // Status = NICInitRecv(pAd); if (Status != NDIS_STATUS_SUCCESS) { goto out; } // // initialize MLME // Status = MlmeInit(pAd); if(Status != NDIS_STATUS_SUCCESS) { goto out; } // Initialize Asics NICInitializeAsic(pAd); // First USB I/O // // Read additional info from NIC such as MAC address // This function must called after register CSR base address //#ifdef INIT_FROM_EEPROM NICReadEEPROMParameters(pAd); NICInitAsicFromEEPROM(pAd);#endif RTUSBWriteHWMACAddress(pAd); // external LNA has different R17 base if (pAd->NicConfig2.field.ExternalLNA) { pAd->BbpTuning.R17LowerBoundA += 0x10; pAd->BbpTuning.R17UpperBoundA += 0x10; pAd->BbpTuning.R17LowerBoundG += 0x10; pAd->BbpTuning.R17UpperBoundG += 0x10; } // hardware initialization after all parameters are acquired from // Registry or E2PROM TmpPhy = pAd->PortCfg.PhyMode; pAd->PortCfg.PhyMode = 0xff; RTMPSetPhyMode(pAd, TmpPhy); // USB_ID info for UI pAd->VendorDesc = 0x148F2573; //pAd->rx_bh.data = (unsigned long)pAd; pAd->rx_bh.func = RTUSBRxPacket; pAd->rx_bk.func = rtusb_bulkrx; CreateThreads(pAd);out: release_module(THIS_MODULE); DBGPRINT(RT_DEBUG_TRACE, "<-- %s: Status = %d\n", __FUNCTION__, Status); return Status;} /* End common_probe () */static int usb_rtusb_open(struct net_device *net_dev){ PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) net_dev->priv; NDIS_STATUS Status = NDIS_STATUS_SUCCESS; DBGPRINT(RT_DEBUG_TRACE, "--> %s: driver version - %s\n", __FUNCTION__, DRIVER_VERSION); KPRINT(KERN_INFO, "driver version - %s\n", DRIVER_VERSION); if (!reserve_module(THIS_MODULE)) { KPRINT(KERN_CRIT, "cannot reserve module\n"); Status = -1; goto out; } if ( !OPSTATUS_TEST_FLAG (pAd,fOP_STATUS_FIRMWARE_LOAD) ) { KPRINT(KERN_ERR, "Firmware not load\n"); DBGPRINT(RT_DEBUG_ERROR, "Firmware not loaded\n"); Status = -EIO; goto out_firmware_error; } RTMP_CLEAR_FLAGS(pAd); // at every open handler, copy mac address. NICInitializeAsic(pAd); // First USB I/O#ifdef INIT_FROM_EEPROM NICInitAsicFromEEPROM(pAd);#endif RTUSBWriteHWMACAddress(pAd); // needed for open after close because CipherAlg lost on close - bb AsicAddSharedKeyEntry(pAd, 0, pAd->PortCfg.DefaultKeyId, pAd->SharedKey[pAd->PortCfg.DefaultKeyId].CipherAlg, pAd->SharedKey[pAd->PortCfg.DefaultKeyId].Key, NULL, NULL); // init mediastate to disconnected OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED); // Clear Reset Flag before starting receiving/transmitting RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS); if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF)) { RTUSBBulkReceive(pAd); RTUSBWriteMACRegister(pAd, TXRX_CSR0, 0x025eb032); // enable RX of MAC block, Staion not drop control frame } MlmeStart(pAd); // Start net_dev interface tx /rx netif_carrier_on(net_dev); // FIXME should reflect state of radio - bb netif_wake_queue(net_dev); /* unlock the device pointers */ up(&(pAd->usbdev_semaphore)); DBGPRINT(RT_DEBUG_TRACE, "<-- %s: OK\n", __FUNCTION__); return 0;out_firmware_error: release_module(THIS_MODULE);out: DBGPRINT(RT_DEBUG_TRACE, "<-- %s: Status=%d\n", __FUNCTION__, Status); return Status;} /* End usb_rtusb_open () */static int usb_rtusb_close(struct net_device *net_dev){ PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) net_dev->priv; DECLARE_WAIT_QUEUE_HEAD (unlink_wakeup); DECLARE_WAITQUEUE (wait, current); DBGPRINT(RT_DEBUG_TRACE,"-->usb_rtusb_close\n"); netif_carrier_off(pAd->net_dev);// FIXME should reflect state of radio - bb netif_stop_queue(pAd->net_dev); // ensure there are no more active urbs. add_wait_queue (&unlink_wakeup, &wait); pAd->wait = &unlink_wakeup; pAd->wait = NULL; remove_wait_queue (&unlink_wakeup, &wait); /* lock the device pointers & shut up compiler under 2.6.26 */ if (down_interruptible(&pAd->usbdev_semaphore)); RTUSBHalt(pAd, TRUE); DBGPRINT(RT_DEBUG_TRACE,"<--usb_rtusb_close\n"); KPRINT(KERN_INFO, "closed\n"); release_module(THIS_MODULE); return 0;}int MlmeThread(void * Context){ PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)Context; DBGPRINT(RT_DEBUG_TRACE,"--> %s\n", __FUNCTION__); rt_daemonize("%s-Mlme", pAd->net_dev->name); allow_signal(SIGTERM); \ set_freezable(); /* Bail on any enabled signal */ while (down_interruptible(&pAd->mlme_semaphore) == 0) { if (try_to_freeze()) continue; /* lock the device pointers , need to check if required*/ if (down_interruptible(&(pAd->usbdev_semaphore))) break; RTMPDeQueuePackets(pAd); // Always call Bulk routine, even reset bulk. // The protectioon of rest bulk should be in BulkOut routine RTUSBKickBulkOut(pAd); RTUSBDequeueRxPackets(pAd); MlmeHandler(pAd); /* unlock the device pointers */ up(&(pAd->usbdev_semaphore)); } /* notify the exit routine that we're actually exiting now * * complete()/wait_for_completion() is similar to up()/down(), * except that complete() is safe in the case where the structure * is getting deleted in a parallel mode of execution (i.e. just * after the down() -- that's necessary for the thread-shutdown * case. * * complete_and_exit() goes even further than this -- it is safe in * the case that the thread of the caller is going away (not just * the structure) -- this is necessary for the module-remove case. * This is important in preemption kernels, which transfer the flow * of execution immediately upon a complete(). */ DBGPRINT(RT_DEBUG_TRACE, "<-- MlmeThread\n"); complete_and_exit (&pAd->mlmenotify, 0);}int RTUSBCmdThread(void * Context){ PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)Context; DBGPRINT(RT_DEBUG_TRACE,"--> %s\n", __FUNCTION__); rt_daemonize("%s-Cmd", pAd->net_dev->name); allow_signal(SIGTERM); \ set_freezable(); /* Bail on any enabled signal */ while (down_interruptible(&pAd->RTUSBCmd_semaphore) == 0) { if (try_to_freeze()) continue; /* lock the device pointers , need to check if required*/ if (down_interruptible(&(pAd->usbdev_semaphore))) break; CMDHandler(pAd); /* unlock the device pointers */ up(&(pAd->usbdev_semaphore)); } /* notify the exit routine that we're actually exiting now * * complete()/wait_for_completion() is similar to up()/down(), * except that complete() is safe in the case where the structure * is getting deleted in a parallel mode of execution (i.e. just * after the down() -- that's necessary for the thread-shutdown * case. * * complete_and_exit() goes even further than this -- it is safe in * the case that the thread of the caller is going away (not just * the structure) -- this is necessary for the module-remove case. * This is important in preemption kernels, which transfer the flow * of execution immediately upon a complete(). */ DBGPRINT(RT_DEBUG_TRACE, "<-- RTUSBCmdThread\n"); complete_and_exit (&pAd->cmdnotify, 0);}#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)#ifdef CONFIG_PMstatic int rt73_pm_callback(struct pm_dev *pdev, pm_request_t rqst, void *data){ DBGPRINT(RT_DEBUG_TRACE, "--> %s\n", __FUNCTION__); switch (rqst) { case PM_SUSPEND: return common_suspend((PRTMP_ADAPTER)data); case PM_RESUME: return common_resume((PRTMP_ADAPTER)data); } DBGPRINT(RT_DEBUG_TRACE, "<-- %s %s\n", __FUNCTION__, data? "ok": "dev not specified"); return data? 0: -EINVAL;}#endifstatic void *usb_rtusb_probe(struct usb_device *dev, UINT interface, const struct usb_device_id *id_table){ PRTMP_ADAPTER pAd; int i; struct net_device *netdev; int res = -ENOMEM; DBGPRINT(RT_DEBUG_TRACE,"--> %s (2.4)\n", __FUNCTION__); usb_get_dev(dev); for (i = 0; i < rtusb_usb_id_len; i++) { if (le16_to_cpu(dev->descriptor.idVendor) == rtusb_usb_id[i].idVendor && le16_to_cpu(dev->descriptor.idProduct) == rtusb_usb_id[i].idProduct) { KPRINT(KERN_INFO, "idVendor = 0x%x, idProduct = 0x%x \n", le16_to_cpu(dev->descriptor.idVendor), le16_to_cpu(dev->descriptor.idProduct)); break; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -