From owner-freebsd-wireless@freebsd.org Sun Aug 19 02:22:24 2018 Return-Path: Delivered-To: freebsd-wireless@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 98C29107EE0F for ; Sun, 19 Aug 2018 02:22:24 +0000 (UTC) (envelope-from khanzf@gmail.com) Received: from mail-qk0-x241.google.com (mail-qk0-x241.google.com [IPv6:2607:f8b0:400d:c09::241]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 3EE90832C9 for ; Sun, 19 Aug 2018 02:22:24 +0000 (UTC) (envelope-from khanzf@gmail.com) Received: by mail-qk0-x241.google.com with SMTP id c126-v6so8759579qkd.7 for ; Sat, 18 Aug 2018 19:22:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:subject:to:message-id:date:user-agent:mime-version :content-language:content-transfer-encoding; bh=SvajxkJN7mABUorELeFC5y/jxeJnXCI2NPVZIVb2xtU=; b=TF2jQSY/NIBVzbLHqHYqwFD/6ouatJF3Lnhb8CI6qDoEE3rPzCK36otnez569Bdq5K xUoc/ctpZ53db45+KsHvGVKHbSp7oyMAqfJUR4IG7UNpc/am2bz5YINP1P8WigFVxxy+ hZ6M/JLN5Ogqr9v26459BNOlqzEXPKnOIkAg+4mODLlQmjNQ1DUUzyZES7Ha92ijj7ma DgiT0Ybumq/UNAv4Otu+lqbAzGStI8iWdljoE6Ctwfef2+6yCKVfX++SgH5W124qOdiY MH99eQaRO/FXhDSJAcSwUGq3BBix4NYIsXQ/Wi+YpS2hRCIOrzxtFmnVVbTQk6fqJM9L I33A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:message-id:date:user-agent :mime-version:content-language:content-transfer-encoding; bh=SvajxkJN7mABUorELeFC5y/jxeJnXCI2NPVZIVb2xtU=; b=FrBqY933kuqe7eIWGP90wuUMHZ5Go0WXeZJXsuoLYPbqYZu4L8zVqBKHx9l9c4apD6 LRkIFBS+pKAeAq211O3JUmEmsG6Z8qVzcVcfuI/x+e7wGJMnHvZDLr/RP8BW/N7g2c0h Uetog5yeGMD58GWX2Rj+h0Cn+xYQ7lv4s7bPyVM3/qRLKs9ghsyEr+piNMQIEWK4zRmC BtJjV1igGdRO/Qewmn6jCK8fr3kbfGebykjPbxN/64Z2H4btZI+oKv2xgGmJxn+kxNsG kPtObxsTBiwrVz7zjmfItl6iacO/CIX7Wbe5/Ia48BR0dMB5Jt2BtmrScOFjIC/aCFNk EOLA== X-Gm-Message-State: AOUpUlFkx6HZrk7ZyTvlLUBbZng4Bw3cFM5k9JusP2Oj0sWcM4uw2PRK pe1c9Dtm+nZE0wsQxyzlmDz5EaVhsS8= X-Google-Smtp-Source: AA+uWPzpw8soGkL1ntVX8ovLZvOZ1hEyJGIFTZZAr8D86+vGHLhd7jp0cxts2cUaaLFGDhjTVZTBtw== X-Received: by 2002:ae9:eb02:: with SMTP id b2-v6mr6984775qkg.24.1534645343230; Sat, 18 Aug 2018 19:22:23 -0700 (PDT) Received: from ?IPv6:2001:470:8:209:ffff:ffff:ffff:ffff? ([2001:470:8:209:ffff:ffff:ffff:ffff]) by smtp.gmail.com with ESMTPSA id s53-v6sm4255404qts.5.2018.08.18.19.22.22 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 18 Aug 2018 19:22:22 -0700 (PDT) From: Farhan Khan Subject: rtwn(4) dropping frames, inconsistently receiving data To: freebsd-wireless@freebsd.org Message-ID: <81b151d7-203e-b50e-27ad-7dc8ec0a2a2b@gmail.com> Date: Sat, 18 Aug 2018 22:22:22 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-wireless@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: "Discussions of 802.11 stack, tools device driver development." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 19 Aug 2018 02:22:24 -0000 Hi all, Update and soliciting advice on my efforts to get rtl8188ee on FreeBSD. High-level summary: The Rx interrupt handler checks the Rx ring to determine if it meets a condition prior to running rtwn_pci_rx_frame(). If it meets the condition, which I suspect is due to the device not yet sending over the data, it will exit rtwn_pci_rx_done() before "processing" the frame any further. This results is dropped packets and/or data arriving in bursts with long delays between them. Verbose explanation: The driver now receives interrupts while in STA mode. This means I see nearby APs when I run "ifconfig wlan0 scan". Great! But these APs/beacon frames are inconsistently picked up the AP. tcpdump(8) shows busts of traffic with large gaps in between. Sometimes a beacon that I see in tcpdump(8) does not show up in the scan cache. Digging deeper, dtrace(1) and printf(1) debugging reveal that: 1. The device is sending interrupts 2. The interrupts are correctly interpreted as Rx, resulting in calling rtwn_pci_rx_done() Here's the problem: From here, the Rx interrupt code checks the current Rx ring if the "rxdw0" value has the RTWN_RXDW0_OWN bit set. If so, it will break, resulting in the frame not being processed. Otherwise, it will run rtwn_pci_rx_frame(), which I understand is what processes the frame (ie, reads beacon frames, updates the scan cache) and terminates. See the following code from rtwn_pci_tx.c. static void rtwn_pci_rx_done(struct rtwn_softc *sc) { struct rtwn_pci_softc *pc = RTWN_PCI_SOFTC(sc); struct rtwn_rx_ring *ring = &pc->rx_ring; bus_dmamap_sync(ring->desc_dmat, ring->desc_map, BUS_DMASYNC_POSTREAD); for (;;) { struct rtwn_rx_stat_pci *rx_desc = &ring->desc[ring->cur]; if (le32toh(rx_desc->rxdw0) & RTWN_RXDW0_OWN) break; rtwn_pci_rx_frame(sc, rx_desc, ring->cur); if (!(sc->sc_flags & RTWN_RUNNING)) return; ring->cur = (ring->cur + 1) % RTWN_PCI_RX_LIST_COUNT; } } I noticed that the majority of the time, and specifically when the "ifconfig wlan0 scan" fails to return anything, the if-condition just above returns true, resulting in the for-loop breaking. My question is, what does checking the RTWN_RXDW0_OWN bit mean? Why is it breaking? Why is data arriving in bursts rather than continuously? Linux Commentary: -------- The commentary in the Linux equivalent, _rtl_pci_rx_interrupt located in drivers/net/wireless/realtek/rtlwifi/pci.c, suggests that this is because the device has not filled out the Rx rings yet: /* wait data to be filled by hardware */ Later down the comment says: /* Reaching this point means: data is filled already ... */ If this is the case, what needs to happen for the device to send data? Why is there a disconnect between the driver interrupt and DMA data? What driver-side configuration issues may be causing this? Ideas? Would hate to be stuck again for a few months :) Thank you, -- Farhan Khan PGP Fingerprint: B28D 2726 E2BC A97E 3854 5ABE 9A9F 00BC D525 16EE