myriadrf / libxtrx

High-level XTRX API library
Apache License 2.0
28 stars 27 forks source link

Cannot reopen device after activating stream using Soapy interface #29

Open joesdiner opened 4 years ago

joesdiner commented 4 years ago

While using the Soapy interface to access an XTRX using the PCIe adapter, I get an error while trying to reopen the device after closing it. This only occurs if I call activateStream() on a stream created from the device. If I do not call activateStream(), it works properly. I have not tested to see if the same problem occurs while using the USB3 adapter.

I am using the latest version of libxtrx with this patch applied to fix setup stream. libxtrxll is the latest and xtrx_linux_pcie_drv is at ab29a2b.

Below is a program exhibiting the behavior I'm observing:

#include "SoapySDR/Device.hpp"
#include "SoapySDR/Formats.hpp"

#include <cassert>
#include <iostream>

void openClose(bool activateStream) {
    int retval;
    static constexpr int Channel = 0;

    SoapySDR::KwargsList devs = SoapySDR::Device::enumerate();
    SoapySDR::Kwargs args = devs[0];
    SoapySDR::Device* sdr = SoapySDR::Device::make(args);
    assert(sdr);

    sdr->setSampleRate(SOAPY_SDR_RX, Channel, 0);
    sdr->setFrequency(SOAPY_SDR_RX, Channel, 30e6);
    sdr->setGain(SOAPY_SDR_RX, Channel, 0);

    SoapySDR::Stream* stream = sdr->setupStream(SOAPY_SDR_RX, SOAPY_SDR_CS16, std::vector<size_t>{Channel});
    assert(stream);

    if (activateStream) {
        retval = sdr->activateStream(stream);
        assert(retval == 0);

        retval = sdr->deactivateStream(stream);
        assert(retval == 0);
    }

    sdr->closeStream(stream);
    SoapySDR::Device::unmake(sdr);
}

int main() {
    std::cout << "===Running test 1===\n";
    openClose(false);
    std::cout << "===Running test 2===\n";
    openClose(false);
    std::cout << "===Running test 3===\n";
    openClose(true);
    std::cout << "===Running test 4===\n";
    openClose(true);
}

Output:

===Running test 1===
10:21:37.659682 DEBUG:  xtrxllpciev0_discovery:263 [PCIE] pcie: Found `pcie:///dev/xtrx0`
10:21:37.672593 DEBUG:  xtrxllpciev0_discovery:263 [PCIE] pcie: Found `pcie:///dev/xtrx0`
[INFO] Make connection: 'pcie:///dev/xtrx0'
10:21:37.677002 INFO:   [XTRX] xtrx_open(): dev[0]='pcie:///dev/xtrx0'
...SNIP...
10:21:37.693861 INFO:   [PCIE] PCI:/dev/xtrx0: Device `pcie:///dev/xtrx0` has been opened successfully
...SNIP...
[INFO] Created: `pcie:///dev/xtrx0`
...SNIP...
10:21:37.956242 INFO:   [PCIE] PCI:/dev/xtrx0: Device is closing
===Running test 2===
[INFO] Make connection: 'pcie:///dev/xtrx0'
10:21:37.977839 INFO:   [XTRX] xtrx_open(): dev[0]='pcie:///dev/xtrx0'
...SNIP...
[INFO] Created: `pcie:///dev/xtrx0`
...SNIP...
10:21:38.254507 INFO:   [PCIE] PCI:/dev/xtrx0: Device is closing
===Running test 3===
[INFO] Make connection: 'pcie:///dev/xtrx0'
10:21:38.276247 INFO:   [XTRX] xtrx_open(): dev[0]='pcie:///dev/xtrx0'
...SNIP...
[INFO] Created: `pcie:///dev/xtrx0`
...SNIP...
10:21:38.564715 INFO:   [XTRX] PCI:/dev/xtrx0: RX initialized to 65536 bytes packet size
10:21:38.564718 INFO:   [BPCI] PCI:/dev/xtrx0: RX DMA 16 bit SISO (BLK:16384 TS:32768); TX DMA SKIP MIMO @0.0
10:21:38.564738 INFO:   [CTRL] PCI:/dev/xtrx0: Placing TC @32768 on 0 data: 0 stat:20
[INFO] SoapyXTRX::activateStream(RX) 0 Samples per packet; res = 0
10:21:38.564745 INFO:   [BPCI] PCI:/dev/xtrx0: RX DMA STOP MIMO (BLK:0 TS:0); TX DMA SKIP MIMO @0.0
10:21:38.564782 INFO:   [LSM7] PCI:/dev/xtrx0: 0x0124[18, 00]
10:21:38.564995 INFO:   [BPCI] PCI:/dev/xtrx0: RX DMA STOP MIMO (BLK:0 TS:0); TX DMA SKIP MIMO @0.0
10:21:38.565096 INFO:   [CTRL] PCI:/dev/xtrx0: RFIC_GPIO 0x000300
10:21:38.566169 INFO:   [PCIE] PCI:/dev/xtrx0: Device is closing
===Running test 4===
[INFO] Make connection: 'pcie:///dev/xtrx0'
10:21:38.584735 INFO:   [XTRX] xtrx_open(): dev[0]='pcie:///dev/xtrx0'
10:21:38.584749 ERROR:  [PCIE] Can't open device `/dev/xtrx0`: Device or resource busy
10:21:38.584756 ERROR:  [USB3] Can't parse device string!
terminate called after throwing an instance of 'std::runtime_error'
  what():  XTRXHandle::XTRXHandle(pcie:///dev/xtrx0) - unable to open the device: error: No such device
Aborted (core dumped)

If I put a pause in between Tests 1 and 2, fuser reports the device is not in use (no output), as expected. If I put a pause between Tests 3 and 4, fuser reports the device is still in use, which it should not be:

$ fuser --verbose /dev/xtrx0
                     USER        PID  ACCESS COMMAND
/dev/xtrx0:          username   18987 ....m a.out
WilfredoLora commented 3 years ago

@joesdiner repo has been updated and the patch has been applied to this repo. Recompile and try again.

Interceptor777 commented 3 years ago

This issue is still present. I am unable to stream Rx from my device and every time the device opens and closes, it's unable to open again.

` ######################################################

Soapy Server -- Use any Soapy SDR remotely

######################################################

Server version: 0.6.0-gc09b2f10 Server UUID: 68b02bf3-9d47-168a-8567-066987a8b523 Launching the server... tcp://[::]:55132 Server bound to [::]:55132 Launching discovery server... Connecting to DNS-SD daemon... [INFO] Avahi version: avahi 0.7 [INFO] Avahi hostname: focal-newport-2 [INFO] Avahi domain: local [INFO] Avahi FQDN: focal-newport-2.local [INFO] avahi_entry_group_add_service(focal-newport-2._soapy._tcp) Press Ctrl+C to stop the server SoapyServerListener::accept([::ffff:168.135.35.100]:43454) 13:52:29.151049 DEBUG: xtrxllpciev0_discovery:263 [PCIE] pcie: Found pcie:///dev/xtrx0 SoapyServerListener::accept([::ffff:168.135.35.100]:43456) SoapyServerListener::close() SoapyServerListener::accept([::ffff:168.135.35.100]:43458) 13:52:29.166040 DEBUG: xtrxllpciev0_discovery:263 [PCIE] pcie: Found pcie:///dev/xtrx0 13:52:29.176227 INFO: [XTRX] xtrx_open(): dev[0]='pcie:///dev/xtrx0' 13:52:29.176417 INFO: [CTRL] PCI:/dev/xtrx0: RFIC_GPIO 0x000300 13:52:29.189171 INFO: [CTRL] PCI:/dev/xtrx0: XTRX Rev4 (04000113) 13:52:29.189239 INFO: [BPCI] PCI:/dev/xtrx0: RX DMA STOP MIMO (BLK:0 TS:0); TX DMA STOP MIMO @0.0 13:52:29.189262 INFO: [PCIE] PCI:/dev/xtrx0: Device pcie:///dev/xtrx0 has been opened successfully 13:52:29.302426 INFO: [CTRL] PCI:/dev/xtrx0: RFIC_GPIO 0x000304 13:52:29.402571 INFO: [CTRL] PCI:/dev/xtrx0: FPGA V_GPIO set to 3280mV 13:52:29.402600 INFO: [CTRL] PCI:/dev/xtrx0: LMS PMIC DCDC out set to VA18=1880mV VA14=1480mV VA12=1340mV 13:52:29.405778 INFO: [CTRL] PCI:/dev/xtrx0: FPGA V_IO set to 1800mV 13:52:29.415871 INFO: [CTRL] PCI:/dev/xtrx0: RFIC_GPIO 0x000306 13:52:29.426286 INFO: [LSM7] PCI:/dev/xtrx0: LMS VER:7 REV:1 MASK:1 (3841) 13:52:29.426316 INFO: [CTRL] PCI:/dev/xtrx0: RFIC_GPIO 0x00031e 13:52:29.428663 INFO: [CTRL] PCI:/dev/xtrx0: RFIC_GPIO 0x00031e 13:52:29.443906 INFO: [XTRX] PCI:/dev/xtrx0: Set INT RefClk to 26000000 based on 26000559 measurement 13:52:29.443958 INFO: [LSM7] PCI:/dev/xtrx0: CGEN: VCO/2=1167360000 k/2=57 int=89 frac=835634 13:52:29.444501 INFO: [LSM7] PCI:/dev/xtrx0: CGEN: binary result: 153 13:52:29.444824 INFO: [LSM7] PCI:/dev/xtrx0: CGEN: Retuned [155:160] -> 157 13:52:29.445016 INFO: [CTRL] PCI:/dev/xtrx0: RFIC_GPIO 0x00031e 13:52:29.445044 INFO: [CTRL] PCI:/dev/xtrx0: FPGA V_IO set to 1800mV 13:52:29.445062 INFO: [LMSF] PCI:/dev/xtrx0: rxrate=2.560MHz txrate=0.000MHz actual_master=20.480MHz rxdecim=2(h_1) txinterp=1(h_1) RX_ADC=5.120MHz TX_DAC=2.560MHz hintr=0 hdecim=0 delay=0 NRXFWD=0 LML1HID=3 LML2HID=1 RX_div=0 TX_div=0 RX_TSP_div=1 TX_TSP_div=1 FclkRX=0.000 (PHS=0) RXx2=0 13:52:29.446161 INFO: [LMSF] PCI:/dev/xtrx0: Set gain 0.0 to 0 on 1 channel 13:52:29.446246 INFO: [LSM7] PCI:/dev/xtrx0: RFE: set_lna(30 -> 30) => 1 13:52:29.448553 INFO: [BPCI] PCI:/dev/xtrx0: RX DMA STOP MIMO (BLK:0 TS:0); TX DMA SKIP MIMO @0.0 13:52:29.448644 INFO: [LSM7] PCI:/dev/xtrx0: 0x0124[00, 00] 13:52:29.448781 INFO: [BPCI] PCI:/dev/xtrx0: RX DMA STOP MIMO (BLK:0 TS:0); TX DMA SKIP MIMO @0.0 13:52:29.448832 INFO: [LMSF] PCI:/dev/xtrx0: Auto RX band selection: LNAL 13:52:29.448878 INFO: [LMSF] PCI:/dev/xtrx0: Set RX band to 2 (L) 13:52:29.449054 INFO: [CTRL] PCI:/dev/xtrx0: RX_ANT: 1 TX_ANT: 0 13:52:29.449080 INFO: [LMSF] PCI:/dev/xtrx0: DC START 13:52:29.449165 INFO: [LSM7] PCI:/dev/xtrx0: 5c1=0000 13:52:29.449210 INFO: [LSM7] PCI:/dev/xtrx0: 5c1=0000 13:52:29.449255 INFO: [LSM7] PCI:/dev/xtrx0: 5c1=0000 13:52:29.449302 INFO: [LSM7] PCI:/dev/xtrx0: 5c1=0000 13:52:29.449374 INFO: [LSM7] PCI:/dev/xtrx0: 5c1=0000 13:52:29.449426 INFO: [LSM7] PCI:/dev/xtrx0: 5c1=0000 13:52:29.449473 INFO: [LSM7] PCI:/dev/xtrx0: 5c1=0000 13:52:29.449519 INFO: [LSM7] PCI:/dev/xtrx0: 5c1=0000 13:52:29.449563 INFO: [LSM7] PCI:/dev/xtrx0: 5c1=0000 13:52:29.449607 INFO: [LSM7] PCI:/dev/xtrx0: 5c1=0000 13:52:29.449686 INFO: [LSM7] PCI:/dev/xtrx0: TX[0]=0000 13:52:29.449764 INFO: [LSM7] PCI:/dev/xtrx0: TX[1]=0000 13:52:29.449841 INFO: [LSM7] PCI:/dev/xtrx0: TX[2]=0000 13:52:29.449919 INFO: [LSM7] PCI:/dev/xtrx0: TX[3]=0000 13:52:29.449998 INFO: [LSM7] PCI:/dev/xtrx0: RX[0]=0000 13:52:29.450082 INFO: [LSM7] PCI:/dev/xtrx0: RX[1]=0000 13:52:29.450163 INFO: [LSM7] PCI:/dev/xtrx0: RX[2]=0000 13:52:29.450241 INFO: [LSM7] PCI:/dev/xtrx0: RX[3]=0000 13:52:29.451575 INFO: [LMSF] PCI:/dev/xtrx0: AFE TX=[0;0] RX=[1;0] 13:52:29.451799 INFO: [LSM7] PCI:/dev/xtrx0: 0x0124[08, 00] 13:52:29.452009 INFO: [LSM7] PCI:/dev/xtrx0: 0x0124[0c, 00] 13:52:29.452464 INFO: [XTRX] PCI:/dev/xtrx0: RX initialized to 65536 bytes packet size 13:52:29.452516 INFO: [BPCI] PCI:/dev/xtrx0: RX DMA 16 bit SISO (BLK:16384 TS:32768); TX DMA SKIP MIMO @0.0 13:52:29.452571 INFO: [CTRL] PCI:/dev/xtrx0: Placing TC @32768 on 0 data: 0 stat:20 13:52:29.462382 INFO: [LMSF] PCI:/dev/xtrx0: FE_FREQ rx=1 type=0 freq=88280000.000000 ch=3 13:52:29.462560 INFO: [LSM7] PCI:/dev/xtrx0: SXR: initial VCO=2824960000 DIVH=5 VCOs:0100 13:52:29.462588 INFO: [LSM7] PCI:/dev/xtrx0: SXX: VCO1 N=108 frac=683994 13:52:29.462884 INFO: [LSM7] PCI:/dev/xtrx0: SXX: binary result: 255 13:52:29.462944 INFO: [LSM7] PCI:/dev/xtrx0: SXR: VCO1 [0;0] -> 0 13:52:29.464036 INFO: [LSM7] PCI:/dev/xtrx0: SXX: VCO1 N=108 frac=683994 13:52:29.464326 INFO: [LSM7] PCI:/dev/xtrx0: SXX: binary result: 109 13:52:29.464478 INFO: [LSM7] PCI:/dev/xtrx0: SXR: VCO1 [109;111] -> 110 13:52:29.464501 INFO: [LSM7] PCI:/dev/xtrx0: SXX: VCO1 N=108 frac=683994 13:52:29.464826 INFO: [LSM7] PCI:/dev/xtrx0: SXX: binary result: 109 13:52:29.464983 INFO: [LSM7] PCI:/dev/xtrx0: SXR: VCO1 [109;111] -> 110 13:52:29.465043 INFO: [LMSF] PCI:/dev/xtrx0: Auto RX band selection: LNAL 13:52:29.465085 INFO: [LMSF] PCI:/dev/xtrx0: Set RX band to 2 (L) 13:52:29.465239 INFO: [CTRL] PCI:/dev/xtrx0: RX_ANT: 1 TX_ANT: 0 13:52:29.465262 INFO: [LMSF] PCI:/dev/xtrx0: DC START 13:52:29.465332 INFO: [LSM7] PCI:/dev/xtrx0: 5c1=0010 13:52:29.465411 INFO: [LSM7] PCI:/dev/xtrx0: 5c1=3020 13:52:29.465460 INFO: [LSM7] PCI:/dev/xtrx0: 5c1=0010 13:52:29.465499 INFO: [LSM7] PCI:/dev/xtrx0: 5c1=0010 13:52:29.465544 INFO: [LSM7] PCI:/dev/xtrx0: 5c1=0010 13:52:29.465589 INFO: [LSM7] PCI:/dev/xtrx0: 5c1=0010 13:52:29.465647 INFO: [LSM7] PCI:/dev/xtrx0: 5c1=0010 13:52:29.465697 INFO: [LSM7] PCI:/dev/xtrx0: 5c1=0010 13:52:29.465746 INFO: [LSM7] PCI:/dev/xtrx0: 5c1=0010 13:52:29.465790 INFO: [LSM7] PCI:/dev/xtrx0: 5c1=0010 13:52:29.465870 INFO: [LSM7] PCI:/dev/xtrx0: TX[0]=0000 13:52:29.465956 INFO: [LSM7] PCI:/dev/xtrx0: TX[1]=0000 13:52:29.466040 INFO: [LSM7] PCI:/dev/xtrx0: TX[2]=0000 13:52:29.466117 INFO: [LSM7] PCI:/dev/xtrx0: TX[3]=0000 13:52:29.466197 INFO: [LSM7] PCI:/dev/xtrx0: RX[0]=0041 13:52:29.466275 INFO: [LSM7] PCI:/dev/xtrx0: RX[1]=0000 13:52:29.466354 INFO: [LSM7] PCI:/dev/xtrx0: RX[2]=0000 13:52:29.466433 INFO: [LSM7] PCI:/dev/xtrx0: RX[3]=0000 13:52:29.466587 INFO: [LMSF] PCI:/dev/xtrx0: NCO ch=1 type=3 freq=0 13:52:29.467283 INFO: [BPCI] PCI:/dev/xtrx0: RX DMA STOP MIMO (BLK:0 TS:0); TX DMA SKIP MIMO @0.0 13:52:29.467349 INFO: [LSM7] PCI:/dev/xtrx0: 0x0124[18, 00] 13:52:29.467478 INFO: [BPCI] PCI:/dev/xtrx0: RX DMA STOP MIMO (BLK:0 TS:0); TX DMA SKIP MIMO @0.0 13:52:29.653394 ERROR: [PCIE] PCI:/dev/xtrx0: Got -32! 13:52:29.727280 INFO: [CTRL] PCI:/dev/xtrx0: RFIC_GPIO 0x000300 13:52:29.728440 INFO: [PCIE] PCI:/dev/xtrx0: Device is closing SoapyServerListener::close() SoapyServerListener::close() SoapyServerListener::accept([::ffff:168.135.35.100]:43460) SoapyServerListener::accept([::ffff:168.135.35.100]:43462) SoapyServerListener::close() SoapyServerListener::accept([::ffff:168.135.35.100]:43464) 13:52:30.601860 INFO: [XTRX] xtrx_open(): dev[0]='pcie:///dev/xtrx0' 13:52:30.602003 ERROR: [PCIE] Can't open device /dev/xtrx0: Device or resource busy 13:52:30.602070 ERROR: [USB3] Can't parse device string! SoapyServerListener::handlerLoop() FAIL: SoapyRPCUnpacker::recv(header) FAIL: SoapyServerListener::close() SoapyServerListener::close()

`