diff --git a/QualcommWifi/QualcommWifi.cpp b/QualcommWifi/QualcommWifi.cpp index c14b632..36f945d 100644 --- a/QualcommWifi/QualcommWifi.cpp +++ b/QualcommWifi/QualcommWifi.cpp @@ -249,7 +249,7 @@ bool QualcommWifi::loadBhiFirmware(void) { IOLog("QualcommWifi: Sonnette BHI_IMGTXDB déclenchée (Session ID = 1, SBL 512 Ko)...\n"); UInt32 bhiStatus = 0; - UInt32 timeoutMs = 3000; + UInt32 timeoutMs = 50; bool sblSuccess = false; while (timeoutMs > 0) { @@ -264,7 +264,7 @@ bool QualcommWifi::loadBhiFirmware(void) { setProperty("BHI_ErrorCode", err, 32); break; } - IODelay(1000); + IODelay(100); timeoutMs--; } @@ -272,7 +272,7 @@ bool QualcommWifi::loadBhiFirmware(void) { setProperty("BHI_Status_Raw", bhiStatus, 32); setProperty("BHI_Status_State", (bhiStatus & ATH12K_BHI_STATUS_MASK) >> ATH12K_BHI_STATUS_SHIFT, 32); - timeoutMs = 2000; + timeoutMs = 50; UInt32 ee = 0; while (timeoutMs > 0) { ee = read32(bhiOff + ATH12K_BHI_EXECENV); @@ -280,7 +280,7 @@ bool QualcommWifi::loadBhiFirmware(void) { if (ee == ATH12K_MHI_EE_SBL || ee == ATH12K_MHI_EE_AMSS || (mhiStat & ATH12K_MHISTATUS_READY_MASK)) { break; } - IODelay(1000); + IODelay(100); timeoutMs--; } @@ -296,13 +296,13 @@ bool QualcommWifi::loadBhiFirmware(void) { uint32_t processedEvents = 0; if (sblSuccess && fDmaPhysAddr != 0) { - timeoutMs = 3000; + timeoutMs = 50; while (timeoutMs > 0) { UInt32 mstat = read32(ATH12K_MHI_MHISTATUS); if (mstat & ATH12K_MHISTATUS_READY_MASK) { break; } - IODelay(1000); + IODelay(100); timeoutMs--; } @@ -427,7 +427,7 @@ bool QualcommWifi::loadBhiFirmware(void) { write32(bhieOff + ATH12K_BHIE_TXVECDB, 0x1); UInt32 bhieStatus = 0; - timeoutMs = 10000; + timeoutMs = 50; while (timeoutMs > 0) { bhieStatus = read32(bhieOff + ATH12K_BHIE_TXVECSTATUS); UInt32 bhieState = (bhieStatus & ATH12K_BHIE_TXVECSTATUS_STATUS_MASK) >> ATH12K_BHIE_TXVECSTATUS_STATUS_SHIFT; @@ -435,7 +435,7 @@ bool QualcommWifi::loadBhiFirmware(void) { amssSuccess = true; break; } - IODelay(1000); + IODelay(100); timeoutMs--; } @@ -447,7 +447,7 @@ bool QualcommWifi::loadBhiFirmware(void) { // Étape 6 : Dépouillement des événements MHI struct mhi_ring_element *erElements = (struct mhi_ring_element *)((uint8_t *)fDmaVirtAddr + 0x4000); - timeoutMs = 5000; + timeoutMs = 50; while (timeoutMs > 0) { UInt32 mstat = read32(ATH12K_MHI_MHISTATUS); UInt32 mstate = (mstat & ATH12K_MHISTATUS_MHISTATE_MASK) >> ATH12K_MHISTATUS_MHISTATE_SHIFT; @@ -480,7 +480,7 @@ bool QualcommWifi::loadBhiFirmware(void) { break; } - IODelay(1000); + IODelay(100); timeoutMs--; } @@ -615,14 +615,9 @@ bool QualcommWifi::start(IOService *provider) { mediumDict->release(); } - if (!IOEthernetController::attachInterface((IONetworkInterface **)&fNetif, true)) { - IOLog("QualcommWifi: Attention - Echec attachement interface reseau BSD.\n"); - } else { - IOLog("QualcommWifi: Interface reseau attachee avec succes (enX) !\n"); - } - + // Enregistrement IOKit du contrôleur Wi-Fi natif (déclenche le matching airportd) registerService(); - IOLog("QualcommWifi: Pilote Wi-Fi natif demarre avec succes !\n"); + IOLog("QualcommWifi: Pilote Wi-Fi natif (IO80211Controller) demarre avec succes !\n"); return true; } @@ -691,39 +686,6 @@ IOReturn QualcommWifi::getHardwareAddress(IOEthernetAddress *addrP) { IOReturn QualcommWifi::enable(IONetworkInterface *netif) { IOLog("QualcommWifi: Interface reseau activee par macOS.\n"); - - if (!fFirmwareLoaded) { - if (allocDmaContext(ATH12K_DMA_TEST_RING_SIZE)) { - setProperty("DMA_PhysAddr", (uint64_t)fDmaPhysAddr, 64); - - int msiIndex = -1; - for (int i = 0; ; i++) { - int intrType = 0; - if (fPciDevice->getInterruptType(i, &intrType) != kIOReturnSuccess) { - break; - } - if (intrType & kIOInterruptTypePCIMessaged) { - msiIndex = i; - break; - } - } - - IOWorkLoop *workLoop = getWorkLoop(); - if (msiIndex >= 0 && workLoop && !fInterruptSource) { - fInterruptSource = IOInterruptEventSource::interruptEventSource( - this, &QualcommWifi::interruptOccurred, fPciDevice, msiIndex); - if (fInterruptSource && workLoop->addEventSource(fInterruptSource) == kIOReturnSuccess) { - fInterruptSource->enable(); - IOLog("QualcommWifi: MSI index %d actif.\n", msiIndex); - } - } - - if (loadBhiFirmware()) { - fFirmwareLoaded = true; - } - } - } - const IONetworkMedium *medium = getSelectedMedium(); setLinkStatus(kIONetworkLinkValid | kIONetworkLinkActive, medium); return kIOReturnSuccess; @@ -768,6 +730,37 @@ IOReturn QualcommWifi::getPOWER(IO80211SkywalkInterface *iface, apple80211_power IOReturn QualcommWifi::setPOWER(IO80211SkywalkInterface *iface, apple80211_power_data *pwr) { int val = (pwr && pwr->power_state[0]) ? 1 : 0; + if (val == 1 && !fFirmwareLoaded && fPciDevice) { + if (allocDmaContext(ATH12K_DMA_TEST_RING_SIZE)) { + setProperty("DMA_PhysAddr", (uint64_t)fDmaPhysAddr, 64); + + int msiIndex = -1; + for (int i = 0; ; i++) { + int intrType = 0; + if (fPciDevice->getInterruptType(i, &intrType) != kIOReturnSuccess) { + break; + } + if (intrType & kIOInterruptTypePCIMessaged) { + msiIndex = i; + break; + } + } + + IOWorkLoop *workLoop = getWorkLoop(); + if (msiIndex >= 0 && workLoop && !fInterruptSource) { + fInterruptSource = IOInterruptEventSource::interruptEventSource( + this, &QualcommWifi::interruptOccurred, fPciDevice, msiIndex); + if (fInterruptSource && workLoop->addEventSource(fInterruptSource) == kIOReturnSuccess) { + fInterruptSource->enable(); + IOLog("QualcommWifi: MSI index %d actif.\n", msiIndex); + } + } + + if (loadBhiFirmware()) { + fFirmwareLoaded = true; + } + } + } return (IOReturn)handleApple80211Request(APPLE80211_IOC_POWER, val, pwr); }